@POST @Path("/{thingUID}/approve") @Consumes(MediaType.TEXT_PLAIN) @ApiOperation(value = "Approves the discovery result by adding the thing to the registry.") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Thing unable to be approved."), @ApiResponse(code = 409, message = "No binding found that supports this thing.") }) public Response approve(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("thingUID") @ApiParam(value = "thingUID", required = true) String thingUID, @ApiParam(value = "thing label") String label) { ThingUID thingUIDObject = new ThingUID(thingUID); String notEmptyLabel = label != null && !label.isEmpty() ? label : null; Thing thing = null; try { thing = inbox.approve(thingUIDObject, notEmptyLabel); } catch (IllegalArgumentException e) { logger.error("Thing {} unable to be approved: {}", thingUID, e.getLocalizedMessage()); return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Thing unable to be approved."); } // inbox.approve returns null if no handler is found that supports this thing if (thing == null) { return JSONResponse.createErrorResponse(Status.CONFLICT, "No binding found that can create the thing"); } return Response.ok(null, MediaType.TEXT_PLAIN).build(); }
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) protected void addInboxAutoApprovePredicate(InboxAutoApprovePredicate inboxAutoApprovePredicate) { inboxAutoApprovePredicates.add(inboxAutoApprovePredicate); for (DiscoveryResult result : inbox.getAll()) { if (result.getFlag().equals(DiscoveryResultFlag.NEW) && inboxAutoApprovePredicate.test(result)) { inbox.approve(result.getThingUID(), result.getLabel()); } } }
@Override public void thingAdded(Inbox inbox, DiscoveryResult result) { if (autoIgnore) { String value = getRepresentationValue(result); if (value != null) { Thing thing = thingRegistry.stream() .filter(t -> Objects.equals(value, getRepresentationPropertyValueForThing(t))) .filter(t -> Objects.equals(t.getThingTypeUID(), result.getThingTypeUID())).findFirst() .orElse(null); if (thing != null) { logger.debug("Auto-ignoring the inbox entry for the representation value {}", value); inbox.setFlag(result.getThingUID(), DiscoveryResultFlag.IGNORED); } } } if (alwaysAutoApprove || isToBeAutoApproved(result)) { inbox.approve(result.getThingUID(), result.getLabel()); } }
@Override public void thingAdded(Inbox inbox, DiscoveryResult result) { if (autoIgnore) { String value = getRepresentationValue(result); if (value != null) { Thing thing = thingRegistry.stream() .filter(t -> Objects.equals(value, getRepresentationPropertyValueForThing(t))) .filter(t -> Objects.equals(t.getUID().getBindingId(), result.getBindingId())).findFirst() .orElse(null); if (thing != null) { logger.debug("Auto-ignoring the inbox entry for the representation value {}", value); inbox.setFlag(result.getThingUID(), DiscoveryResultFlag.IGNORED); } } } if (autoApprove) { inbox.approve(result.getThingUID(), result.getLabel()); } }
private void approveAllInboxEntries() { for (DiscoveryResult result : inbox.getAll()) { if (result.getFlag().equals(DiscoveryResultFlag.NEW)) { inbox.approve(result.getThingUID(), result.getLabel()); } } }
private void autoApproveInboxEntries() { for (DiscoveryResult result : inbox.getAll()) { if (result.getFlag().equals(DiscoveryResultFlag.NEW)) { if (alwaysAutoApprove || isToBeAutoApproved(result)) { inbox.approve(result.getThingUID(), result.getLabel()); } } } }
return; inbox.approve(thingUID, label); } catch (Exception e) { console.println(e.getMessage());
return; inbox.approve(thingUID, label); } catch (IllegalArgumentException e) { console.println(e.getMessage());