use of org.thingsboard.server.common.data.id.EntityId in project thingsboard by thingsboard.
the class EntityRelationController method findInfoByFrom.
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = { FROM_ID, FROM_TYPE })
@ResponseBody
public List<EntityRelationInfo> findInfoByFrom(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
checkParameter(FROM_ID, strFromId);
checkParameter(FROM_TYPE, strFromType);
EntityId entityId = EntityIdFactory.getByTypeAndId(strFromType, strFromId);
checkEntityId(entityId);
RelationTypeGroup typeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
try {
return checkNotNull(relationService.findInfoByFrom(entityId, typeGroup).get());
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.id.EntityId in project thingsboard by thingsboard.
the class EntityRelationController method deleteRelation.
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relation", method = RequestMethod.DELETE, params = { FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE })
@ResponseStatus(value = HttpStatus.OK)
public void deleteRelation(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @RequestParam(RELATION_TYPE) String strRelationType, @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup, @RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
checkParameter(FROM_ID, strFromId);
checkParameter(FROM_TYPE, strFromType);
checkParameter(RELATION_TYPE, strRelationType);
checkParameter(TO_ID, strToId);
checkParameter(TO_TYPE, strToType);
EntityId fromId = EntityIdFactory.getByTypeAndId(strFromType, strFromId);
EntityId toId = EntityIdFactory.getByTypeAndId(strToType, strToId);
checkEntityId(fromId);
checkEntityId(toId);
RelationTypeGroup relationTypeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
try {
Boolean found = relationService.deleteRelation(fromId, toId, strRelationType, relationTypeGroup);
if (!found) {
throw new ThingsboardException("Requested item wasn't found!", ThingsboardErrorCode.ITEM_NOT_FOUND);
}
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.id.EntityId in project thingsboard by thingsboard.
the class EntityRelationController method deleteRelations.
@PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relations", method = RequestMethod.DELETE, params = { "id", "type" })
@ResponseStatus(value = HttpStatus.OK)
public void deleteRelations(@RequestParam("entityId") String strId, @RequestParam("entityType") String strType) throws ThingsboardException {
checkParameter("entityId", strId);
checkParameter("entityType", strType);
EntityId entityId = EntityIdFactory.getByTypeAndId(strType, strId);
checkEntityId(entityId);
try {
relationService.deleteEntityRelations(entityId);
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.id.EntityId in project thingsboard by thingsboard.
the class TelemetryRestMsgHandler method handleHttpGetRequest.
@Override
public void handleHttpGetRequest(PluginContext ctx, PluginRestMsg msg) throws ServletException {
RestRequest request = msg.getRequest();
String[] pathParams = request.getPathParams();
if (pathParams.length < 4) {
msg.getResponseHolder().setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
return;
}
String entityType = pathParams[0];
String entityIdStr = pathParams[1];
String method = pathParams[2];
TelemetryFeature feature = TelemetryFeature.forName(pathParams[3]);
String scope = pathParams.length >= 5 ? pathParams[4] : null;
if (StringUtils.isEmpty(entityType) || EntityType.valueOf(entityType) == null || StringUtils.isEmpty(entityIdStr) || StringUtils.isEmpty(method) || StringUtils.isEmpty(feature)) {
msg.getResponseHolder().setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
return;
}
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr);
if (method.equals("keys")) {
handleHttpGetKeysMethod(ctx, msg, feature, scope, entityId);
} else if (method.equals("values")) {
handleHttpGetValuesMethod(ctx, msg, request, feature, scope, entityId);
}
}
use of org.thingsboard.server.common.data.id.EntityId in project thingsboard by thingsboard.
the class TelemetryRestMsgHandler method handleHttpPostRequest.
@Override
public void handleHttpPostRequest(PluginContext ctx, PluginRestMsg msg) throws ServletException {
RestRequest request = msg.getRequest();
Exception error = null;
try {
String[] pathParams = request.getPathParams();
EntityId entityId;
String scope;
long ttl = 0L;
TelemetryFeature feature;
if (pathParams.length == 2) {
entityId = DeviceId.fromString(pathParams[0]);
scope = pathParams[1];
feature = TelemetryFeature.ATTRIBUTES;
} else if (pathParams.length == 3) {
entityId = EntityIdFactory.getByTypeAndId(pathParams[0], pathParams[1]);
scope = pathParams[2];
feature = TelemetryFeature.ATTRIBUTES;
} else if (pathParams.length == 4) {
entityId = EntityIdFactory.getByTypeAndId(pathParams[0], pathParams[1]);
feature = TelemetryFeature.forName(pathParams[2].toUpperCase());
scope = pathParams[3];
} else if (pathParams.length == 5) {
entityId = EntityIdFactory.getByTypeAndId(pathParams[0], pathParams[1]);
feature = TelemetryFeature.forName(pathParams[2].toUpperCase());
scope = pathParams[3];
ttl = Long.parseLong(pathParams[4]);
} else {
msg.getResponseHolder().setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
return;
}
if (feature == TelemetryFeature.ATTRIBUTES) {
if (handleHttpPostAttributes(ctx, msg, request, entityId, scope)) {
return;
}
} else if (feature == TelemetryFeature.TIMESERIES) {
handleHttpPostTimeseries(ctx, msg, request, entityId, ttl);
return;
}
} catch (IOException | RuntimeException e) {
log.debug("Failed to process POST request due to exception", e);
error = e;
}
handleError(error, msg, HttpStatus.BAD_REQUEST);
}
Aggregations