Add missing getRelation method.
This commit is contained in:
parent
8e272b0162
commit
b2ac8f6447
@ -97,8 +97,8 @@ public class EntityRelationController extends BaseController {
|
|||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/relation", method = RequestMethod.GET, params = {"fromId", "fromType", "relationType", "toId", "toType"})
|
@RequestMapping(value = "/relation", method = RequestMethod.GET, params = {"fromId", "fromType", "relationType", "toId", "toType"})
|
||||||
@ResponseStatus(value = HttpStatus.OK)
|
@ResponseBody
|
||||||
public void checkRelation(@RequestParam("fromId") String strFromId,
|
public EntityRelation getRelation(@RequestParam("fromId") String strFromId,
|
||||||
@RequestParam("fromType") String strFromType,
|
@RequestParam("fromType") String strFromType,
|
||||||
@RequestParam("relationType") String strRelationType,
|
@RequestParam("relationType") String strRelationType,
|
||||||
@RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup,
|
@RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup,
|
||||||
@ -114,10 +114,7 @@ public class EntityRelationController extends BaseController {
|
|||||||
checkEntityId(fromId);
|
checkEntityId(fromId);
|
||||||
checkEntityId(toId);
|
checkEntityId(toId);
|
||||||
RelationTypeGroup typeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
|
RelationTypeGroup typeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
|
||||||
Boolean found = relationService.checkRelation(fromId, toId, strRelationType, typeGroup).get();
|
return checkNotNull(relationService.getRelation(fromId, toId, strRelationType, typeGroup).get());
|
||||||
if (!found) {
|
|
||||||
throw new ThingsboardException("Requested item wasn't found!", ThingsboardErrorCode.ITEM_NOT_FOUND);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,6 +127,19 @@ public class BaseRelationDao extends CassandraAbstractAsyncDao implements Relati
|
|||||||
return getFuture(executeAsyncRead(stmt), rs -> rs != null ? rs.one() != null : false);
|
return getFuture(executeAsyncRead(stmt), rs -> rs != null ? rs.one() != null : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<EntityRelation> getRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) {
|
||||||
|
BoundStatement stmt = getCheckRelationStmt().bind()
|
||||||
|
.setUUID(0, from.getId())
|
||||||
|
.setString(1, from.getEntityType().name())
|
||||||
|
.setUUID(2, to.getId())
|
||||||
|
.setString(3, to.getEntityType().name())
|
||||||
|
.set(4, typeGroup, relationTypeGroupCodec)
|
||||||
|
.setString(5, relationType);
|
||||||
|
return getFuture(executeAsyncRead(stmt), rs -> rs != null ? getEntityRelation(rs.one()) : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Boolean> saveRelation(EntityRelation relation) {
|
public ListenableFuture<Boolean> saveRelation(EntityRelation relation) {
|
||||||
BoundStatement stmt = getSaveStmt().bind()
|
BoundStatement stmt = getSaveStmt().bind()
|
||||||
|
|||||||
@ -55,6 +55,13 @@ public class BaseRelationService implements RelationService {
|
|||||||
return relationDao.checkRelation(from, to, relationType, typeGroup);
|
return relationDao.checkRelation(from, to, relationType, typeGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<EntityRelation> getRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) {
|
||||||
|
log.trace("Executing EntityRelation [{}][{}][{}][{}]", from, to, relationType, typeGroup);
|
||||||
|
validate(from, to, relationType, typeGroup);
|
||||||
|
return relationDao.getRelation(from, to, relationType, typeGroup);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Boolean> saveRelation(EntityRelation relation) {
|
public ListenableFuture<Boolean> saveRelation(EntityRelation relation) {
|
||||||
log.trace("Executing saveRelation [{}]", relation);
|
log.trace("Executing saveRelation [{}]", relation);
|
||||||
|
|||||||
@ -39,6 +39,8 @@ public interface RelationDao {
|
|||||||
|
|
||||||
ListenableFuture<Boolean> checkRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup);
|
ListenableFuture<Boolean> checkRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup);
|
||||||
|
|
||||||
|
ListenableFuture<EntityRelation> getRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup);
|
||||||
|
|
||||||
ListenableFuture<Boolean> saveRelation(EntityRelation relation);
|
ListenableFuture<Boolean> saveRelation(EntityRelation relation);
|
||||||
|
|
||||||
ListenableFuture<Boolean> deleteRelation(EntityRelation relation);
|
ListenableFuture<Boolean> deleteRelation(EntityRelation relation);
|
||||||
|
|||||||
@ -30,6 +30,8 @@ public interface RelationService {
|
|||||||
|
|
||||||
ListenableFuture<Boolean> checkRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup);
|
ListenableFuture<Boolean> checkRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup);
|
||||||
|
|
||||||
|
ListenableFuture<EntityRelation> getRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup);
|
||||||
|
|
||||||
ListenableFuture<Boolean> saveRelation(EntityRelation relation);
|
ListenableFuture<Boolean> saveRelation(EntityRelation relation);
|
||||||
|
|
||||||
ListenableFuture<Boolean> deleteRelation(EntityRelation relation);
|
ListenableFuture<Boolean> deleteRelation(EntityRelation relation);
|
||||||
|
|||||||
@ -108,6 +108,18 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
|
|||||||
return service.submit(() -> relationRepository.findOne(key) != null);
|
return service.submit(() -> relationRepository.findOne(key) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<EntityRelation> getRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) {
|
||||||
|
RelationCompositeKey key =
|
||||||
|
new RelationCompositeKey(from.getId(),
|
||||||
|
from.getEntityType().name(),
|
||||||
|
to.getId(),
|
||||||
|
to.getEntityType().name(),
|
||||||
|
relationType,
|
||||||
|
typeGroup.name());
|
||||||
|
return service.submit(() -> DaoUtil.getData(relationRepository.findOne(key)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Boolean> saveRelation(EntityRelation relation) {
|
public ListenableFuture<Boolean> saveRelation(EntityRelation relation) {
|
||||||
return service.submit(() -> relationRepository.save(new RelationEntity(relation)) != null);
|
return service.submit(() -> relationRepository.save(new RelationEntity(relation)) != null);
|
||||||
|
|||||||
@ -24,6 +24,7 @@ function EntityRelationService($http, $q) {
|
|||||||
saveRelation: saveRelation,
|
saveRelation: saveRelation,
|
||||||
deleteRelation: deleteRelation,
|
deleteRelation: deleteRelation,
|
||||||
deleteRelations: deleteRelations,
|
deleteRelations: deleteRelations,
|
||||||
|
getRelation: getRelation,
|
||||||
findByFrom: findByFrom,
|
findByFrom: findByFrom,
|
||||||
findInfoByFrom: findInfoByFrom,
|
findInfoByFrom: findInfoByFrom,
|
||||||
findByFromAndType: findByFromAndType,
|
findByFromAndType: findByFromAndType,
|
||||||
@ -74,6 +75,20 @@ function EntityRelationService($http, $q) {
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRelation(fromId, fromType, relationType, toId, toType) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
var url = '/api/relation?fromId=' + fromId;
|
||||||
|
url += '&fromType=' + fromType;
|
||||||
|
url += '&relationType=' + relationType;
|
||||||
|
url += '&toId=' + toId;
|
||||||
|
url += '&toType=' + toType;
|
||||||
|
$http.get(url).then(function success(response) {
|
||||||
|
deferred.resolve(response.data);
|
||||||
|
}, function fail() {
|
||||||
|
deferred.reject();
|
||||||
|
});
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
function findByFrom(fromId, fromType) {
|
function findByFrom(fromId, fromType) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|||||||
@ -34,9 +34,23 @@ export default function EntityAutocomplete($compile, $templateCache, $q, $filter
|
|||||||
|
|
||||||
scope.fetchEntities = function(searchText) {
|
scope.fetchEntities = function(searchText) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
entityService.getEntitiesByNameFilter(scope.entityType, searchText, 50, null, scope.entitySubtype).then(function success(result) {
|
var limit = 50;
|
||||||
|
if (scope.excludeEntityIds && scope.excludeEntityIds.length) {
|
||||||
|
limit += scope.excludeEntityIds.length;
|
||||||
|
}
|
||||||
|
entityService.getEntitiesByNameFilter(scope.entityType, searchText, limit, null, scope.entitySubtype).then(function success(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
|
if (scope.excludeEntityIds && scope.excludeEntityIds.length) {
|
||||||
|
var entities = [];
|
||||||
|
result.forEach(function(entity) {
|
||||||
|
if (scope.excludeEntityIds.indexOf(entity.id.id) == -1) {
|
||||||
|
entities.push(entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
deferred.resolve(entities);
|
||||||
|
} else {
|
||||||
deferred.resolve(result);
|
deferred.resolve(result);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
deferred.resolve([]);
|
deferred.resolve([]);
|
||||||
}
|
}
|
||||||
@ -165,7 +179,8 @@ export default function EntityAutocomplete($compile, $templateCache, $q, $filter
|
|||||||
tbRequired: '=?',
|
tbRequired: '=?',
|
||||||
disabled:'=ngDisabled',
|
disabled:'=ngDisabled',
|
||||||
entityType: '=',
|
entityType: '=',
|
||||||
entitySubtype: '=?'
|
entitySubtype: '=?',
|
||||||
|
excludeEntityIds: '=?'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user