Skip to content

Commit

Permalink
Checking if gateway access is authorized in Objenious
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoder committed Mar 19, 2024
1 parent 9114e50 commit 191b061
Showing 1 changed file with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import c8y.ConnectionState;
import feign.Feign;
import feign.FeignException.FeignClientException;
import feign.Logger.Level;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
Expand Down Expand Up @@ -196,29 +197,37 @@ public void deprovisionDevice(String deveui) {
public List<Gateway> getGateways() {
logger.info("Getting list of gateways with connector {}...", this.getName());
List<Gateway> result = new ArrayList<>();
var gateways = objeniousService.getGateways();
gateways.forEach(g -> {
logger.info("Got gateway {}", g.getGatewayName());
C8YData data = new C8YData();
ConnectionState state = ConnectionState.AVAILABLE;
switch (g.getStatus()) {
case ACTIVE:
state = ConnectionState.AVAILABLE;
break;
case ALERT:
state = ConnectionState.AVAILABLE;
break;
case INACTIVE:
state = ConnectionState.UNAVAILABLE;
break;
default:
break;
try {
var gateways = objeniousService.getGateways();
gateways.forEach(g -> {
logger.info("Got gateway {}", g.getGatewayName());
C8YData data = new C8YData();
ConnectionState state = ConnectionState.AVAILABLE;
switch (g.getStatus()) {
case ACTIVE:
state = ConnectionState.AVAILABLE;
break;
case ALERT:
state = ConnectionState.AVAILABLE;
break;
case INACTIVE:
state = ConnectionState.UNAVAILABLE;
break;
default:
break;
}
Gateway gateway = new Gateway(g.getGatewayId(), g.getSerialNumber(), g.getGatewayName(),
BigDecimal.valueOf(g.getLat()), BigDecimal.valueOf(g.getLng()), g.getGatewayType(),
state, data);
result.add(gateway);
});
} catch (FeignClientException e) {
if (e.status() == 403) {
logger.error("Gateway access is forbidden with this account.", e);
} else {
throw e;
}
Gateway gateway = new Gateway(g.getGatewayId(), g.getSerialNumber(), g.getGatewayName(),
BigDecimal.valueOf(g.getLat()), BigDecimal.valueOf(g.getLng()), g.getGatewayType(), state,
data);
result.add(gateway);
});
}
return result;
}

Expand Down

0 comments on commit 191b061

Please sign in to comment.