@Given("^Account for \"(.*)\"$") public void getAccountForName(String accountName) throws KapuaException { Account account = accountService.findByName(accountName); stepData.put("LastAccount", account); }
public KapuaId getScopeId() throws KapuaException { return KapuaSecurityUtils.doPrivileged(() -> accountService.findByName(scope).getId()); }
@Given("^A full set of device privileges for account \"(.+)\"$") public void setAccountDevicePrivileges(String name) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { Account account = accountService.findByName(name); Map<String, Object> valueMap = new HashMap<>(); valueMap.put("infiniteChildEntities", true); valueMap.put("maxNumberChildEntities", 1000); deviceRegistryService.setConfigValues(account.getId(), account.getScopeId(), valueMap); }); }
@Given("^The default connection coupling mode for account \"(.+)\" is set to \"(.+)\"$") public void setDeviceConnectionCouplingMode(String name, String mode) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { Account account = accountService.findByName(name); Map<String, Object> valueMap = new HashMap<>(); // valueMap.put("infiniteChildEntities", true); // valueMap.put("maxNumberChildEntities", 1000); valueMap.put("deviceConnectionUserCouplingDefaultMode", mode); deviceConnectionService.setConfigValues(account.getId(), account.getScopeId(), valueMap); }); }
@When("^I select account \"(.*)\"$") public void selectAccount(String accountName) throws KapuaException { Account tmpAccount; tmpAccount = accountService.findByName(accountName); if (tmpAccount != null) { stepData.put("LastAccount", tmpAccount); } else { stepData.remove("LastAccount"); } }
private KapuaConnectionContext parseTopicInfo(javax.jms.Message message) throws JMSException, KapuaException { String originalTopic = message.getStringProperty(MessageConstants.PROPERTY_ORIGINAL_TOPIC); String topic[] = originalTopic.split("\\."); if (topic.length != 5) { logger.error("Invalid topic format. Cannot process connect message."); throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, "wrong connect message topic"); } String accountName = topic[1]; String clientId = topic[2]; Account account = KapuaSecurityUtils.doPrivileged(() -> accountService.findByName(accountName)); Long scopeId = account.getId().getId().longValue(); return new KapuaConnectionContext(scopeId, clientId, MULTI_ACCOUNT_CLIENT_ID); }
@When("^I try to delete account \"(.*)\"$") public void deleteAccount(String accountName) throws KapuaException { Account accountToDelete; accountToDelete = accountService.findByName(accountName); if (accountToDelete != null) { accountService.delete(accountToDelete.getScopeId(), accountToDelete.getId()); } }
@When("^I set the reserved user for the connection from device \"(.+)\" in account \"(.+)\" to \"(.*)\"$") public void modifyDeviceConnectionReservedUser(String device, String scope, String resUser) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { Account tmpAcc = accountService.findByName(scope); DeviceConnection tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), device); KapuaId userId; Assert.assertNotNull(tmpConn); if (resUser.isEmpty() || resUser.trim().toLowerCase().contains("null")) { userId = null; } else { userId = userService.findByName(resUser).getId(); } tmpConn.setReservedUserId(userId); stepData.put("ExceptionCaught", false); try { primeException(); deviceConnectionService.update(tmpConn); } catch (KapuaException ex) { verifyException(ex); } catch (Exception e) { int a = 10; } }); }
@When("^I set the user change flag for the connection from device \"(.+)\" in account \"(.+)\" to \"(.+)\"$") public void modifyDeviceConnectionUserChangeFlag(String device, String account, String flag) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { Account tmpAcc = accountService.findByName(account); DeviceConnection tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), device); Assert.assertNotNull(tmpConn); tmpConn.setAllowUserChange(parseBooleanFromString(flag)); deviceConnectionService.update(tmpConn); }); }
@Given("^Such a set of privileged users for account \"(.+)\"$") public void createPrivilegedUsers(String accName, List<TestUser> users) throws Throwable { KapuaSecurityUtils.doPrivileged(() -> { Account account = accountService.findByName(accName); for (TestUser tmpTestUsr : users) { User tmpUser = aclCreator.createUser(account, tmpTestUsr.getName()); if ((tmpTestUsr.getPassword() != null) && !tmpTestUsr.getPassword().isEmpty()) { aclCreator.attachUserCredentials(account, tmpUser, tmpTestUsr.getPassword()); } else { aclCreator.attachUserCredentials(account, tmpUser); } aclCreator.attachFullPermissions(account, tmpUser); } }); }
@When("^I search for the device \"(.+)\" in account \"(.+)\"$") public void searchForDeviceWithClientID(String clientId, String account) throws KapuaException { Account tmpAcc; Device tmpDev; DeviceListResult tmpList = new DeviceListResultImpl(); tmpAcc = KapuaLocator.getInstance().getService(AccountService.class).findByName(account); Assert.assertNotNull(tmpAcc); Assert.assertNotNull(tmpAcc.getId()); tmpDev = deviceRegistryService.findByClientId(tmpAcc.getId(), clientId); if (tmpDev != null) { Vector<Device> dv = new Vector<>(); dv.add(tmpDev); tmpList.addItems(dv); stepData.put("Device", tmpDev); stepData.put("DeviceList", tmpList); } }
@Override public TO_M translate(KuraResponseMessage kuraMessage) throws KapuaException { final KapuaLocator locator = KapuaLocator.getInstance(); final AccountService accountService = locator.getService(AccountService.class); final Account account = KapuaSecurityUtils.doPrivileged(() -> accountService.findByName(kuraMessage.getChannel().getScope())); if (account == null) { throw new KapuaEntityNotFoundException(Account.TYPE, kuraMessage.getChannel().getScope()); } return translateMessage(kuraMessage, account); }
@When("^I set the user coupling mode for the connection from device \"(.+)\" in account \"(.+)\" to \"(.+)\"$") public void modifyDeviceConnectionCouplingMode(String device, String account, String mode) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { ConnectionUserCouplingMode tmpMode = parseConnectionCouplingString(mode); Assert.assertNotNull(tmpMode); Account tmpAcc = accountService.findByName(account); DeviceConnection tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), device); Assert.assertNotNull(tmpConn); tmpConn.setUserCouplingMode(tmpMode); deviceConnectionService.update(tmpConn); }); }
@When("^I set the connection status from the device \"(.+)\" in account \"(.+)\" to \"(.+)\"$") public void modifyDeviceConnectionStatus(String device, String account, String status) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { Account tmpAcc = accountService.findByName(account); DeviceConnection tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), device); DeviceConnectionStatus tmpStat = parseConnectionStatusString(status); Assert.assertNotNull(tmpStat); Assert.assertNotNull(tmpConn); tmpConn.setStatus(tmpStat); deviceConnectionService.update(tmpConn); }); }
@When("^I search for a connection from the device \"(.+)\" in account \"(.+)\"$") public void searchForConnectionFromDeviceWithClientID(String clientId, String account) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { Account tmpAcc; DeviceConnection tmpConn; DeviceConnectionListResult tmpConnLst = new DeviceConnectionListResultImpl(); tmpAcc = accountService.findByName(account); Assert.assertNotNull(tmpAcc); Assert.assertNotNull(tmpAcc.getId()); tmpConn = deviceConnectionService.findByClientId(tmpAcc.getId(), clientId); Map<String, Object> props = deviceRegistryService.getConfigValues(tmpAcc.getId()); stepData.put("DeviceConnection", tmpConn); if (tmpConn != null) { Vector<DeviceConnection> dcv = new Vector<>(); dcv.add(tmpConn); tmpConnLst.addItems(dcv); } stepData.put("DeviceConnectionList", tmpConnLst); }); }
@Override public TO_M translate(KuraResponseMessage kuraMessage) throws KapuaException { final KapuaLocator locator = KapuaLocator.getInstance(); final AccountService accountService = locator.getService(AccountService.class); final Account account = KapuaSecurityUtils.doPrivileged(() -> accountService.findByName(kuraMessage.getChannel().getScope())); if (account == null) { throw new KapuaEntityNotFoundException(Account.TYPE, kuraMessage.getChannel().getScope()); } return translateMessage(kuraMessage, account); }
@Then("^The user for the connection from device \"(.+)\" in scope \"(.+)\" is \"(.+)\"$") public void checkUserForExistingConnection(String device, String scope, String name) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { Account account = accountService.findByName(scope); DeviceConnection connection = deviceConnectionService.findByClientId(account.getId(), device); User user = userService.findByName(name); Assert.assertNotNull(connection); Assert.assertNotNull(user); Assert.assertEquals(user.getId(), connection.getUserId()); }); }
@When("^I search for events from device \"(.+)\" in account \"(.+)\"$") public void searchForEventsFromDeviceWithClientID(String clientId, String account) throws KapuaException { DeviceEventQuery tmpQuery; Device tmpDev; DeviceEventListResult tmpList; Account tmpAcc; tmpAcc = KapuaLocator.getInstance().getService(AccountService.class).findByName(account); Assert.assertNotNull(tmpAcc); Assert.assertNotNull(tmpAcc.getId()); tmpDev = deviceRegistryService.findByClientId(tmpAcc.getId(), clientId); Assert.assertNotNull(tmpDev); Assert.assertNotNull(tmpDev.getId()); tmpQuery = new DeviceEventQueryImpl(tmpAcc.getId()); tmpQuery.setPredicate(AttributePredicateImpl.attributeIsEqualTo("deviceId", tmpDev.getId())); tmpQuery.setSortCriteria(new FieldSortCriteria("receivedOn", FieldSortCriteria.SortOrder.ASCENDING)); tmpList = deviceEventsService.query(tmpQuery); Assert.assertNotNull(tmpList); stepData.put("DeviceEventList", tmpList); }
@Override public KapuaUnmatchedMessage translate(KuraUnmatchedMessage kuraUnmatchedMessage) throws KapuaException { KapuaUnmatchedMessage kapuaUnmatchedMessage = new KapuaUnmatchedMessageImpl(); kapuaUnmatchedMessage.setChannel(translate(kuraUnmatchedMessage.getChannel())); kapuaUnmatchedMessage.setPayload(translate(kuraUnmatchedMessage.getPayload())); KapuaLocator locator = KapuaLocator.getInstance(); AccountService accountService = locator.getService(AccountService.class); Account account = accountService.findByName(kuraUnmatchedMessage.getChannel().getScope()); if (account == null) { throw new KapuaEntityNotFoundException(Account.TYPE, kuraUnmatchedMessage.getChannel().getScope()); } // no device information since may it uses an mqtt connection pooling with devices not registered in the device tables kapuaUnmatchedMessage.setScopeId(account.getId()); kapuaUnmatchedMessage.setCapturedOn(kuraUnmatchedMessage.getPayload().getTimestamp()); kapuaUnmatchedMessage.setSentOn(kuraUnmatchedMessage.getPayload().getTimestamp()); kapuaUnmatchedMessage.setReceivedOn(kuraUnmatchedMessage.getTimestamp()); kapuaUnmatchedMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraUnmatchedMessage.getPayload().getPosition())); return kapuaUnmatchedMessage; }
@Override public KapuaUnmatchedMessage translate(KuraUnmatchedMessage kuraUnmatchedMessage) throws KapuaException { KapuaUnmatchedMessage kapuaUnmatchedMessage = new KapuaUnmatchedMessageImpl(); kapuaUnmatchedMessage.setChannel(translate(kuraUnmatchedMessage.getChannel())); kapuaUnmatchedMessage.setPayload(translate(kuraUnmatchedMessage.getPayload())); KapuaLocator locator = KapuaLocator.getInstance(); AccountService accountService = locator.getService(AccountService.class); Account account = accountService.findByName(kuraUnmatchedMessage.getChannel().getScope()); if (account == null) { throw new KapuaEntityNotFoundException(Account.TYPE, kuraUnmatchedMessage.getChannel().getScope()); } // no device information since may it uses an mqtt connection pooling with devices not registered in the device tables kapuaUnmatchedMessage.setScopeId(account.getId()); kapuaUnmatchedMessage.setCapturedOn(kuraUnmatchedMessage.getPayload().getTimestamp()); kapuaUnmatchedMessage.setSentOn(kuraUnmatchedMessage.getPayload().getTimestamp()); kapuaUnmatchedMessage.setReceivedOn(kuraUnmatchedMessage.getTimestamp()); kapuaUnmatchedMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraUnmatchedMessage.getPayload().getPosition())); return kapuaUnmatchedMessage; }