/** * Returns the Account specified by the "accountId" path parameter. * * @param scopeId * The {@link ScopeId} of the requested {@link Account}. * @param accountId * The id of the requested Account. * @return The requested Account object. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "accountFind", value = "Get an Account", // notes = "Returns the Account specified by the \"accountId\" path parameter.", // response = Account.class) @GET @Path("{accountId}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Account find( @ApiParam(value = "The ScopeId of the requested Account.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, // @ApiParam(value = "The id of the requested Account", required = true) @PathParam("accountId") EntityId accountId) throws Exception { Account account = accountService.find(scopeId, accountId); if (account == null) { throw new KapuaEntityNotFoundException(Account.TYPE, accountId); } return account; }
@Given("^Account for \"(.*)\"$") public void getAccountForName(String accountName) throws KapuaException { Account account = accountService.findByName(accountName); stepData.put("LastAccount", account); }
/** * Creates a new Account based on the information provided in AccountCreator * parameter. * * @param scopeId * The {@link ScopeId} in which to create the {@link Account} * @param accountCreator * Provides the information for the new {@link Account} to be created. * @return The newly created {@link Account} object. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "accountCreate", value = "Create an Account", // notes = "Creates a new Account based on the information provided in AccountCreator parameter.", // response = Account.class) @POST @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Account create( @ApiParam(value = "The ScopeId in which to create the Account", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, // @ApiParam(value = "Provides the information for the new Account to be created", required = true) AccountCreator accountCreator) throws Exception { accountCreator.setScopeId(scopeId); return accountService.create(accountCreator); }
@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()); } }
/** * Queries the results with the given {@link AccountQuery} parameter. * * @param scopeId * The {@link ScopeId} in which to search results. * @param query * The {@link AccountQuery} to use to filter results. * @return The {@link AccountListResult} of all the result matching the given {@link AccountQuery} parameter. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "accountQuery", value = "Queries the Accounts", // notes = "Queries the Accounts with the given AccountQuery parameter returning all matching Accounts", // response = AccountListResult.class) // @POST @Path("_query") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public AccountListResult query( @ApiParam(value = "The ScopeId in which to search results.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, // @ApiParam(value = "The AccountQuery to use to filter results.", required = true) AccountQuery query) throws Exception { query.setScopeId(scopeId); return accountService.query(query); }
/** * Updates the Account based on the information provided in the Account parameter. * * @param scopeId * The ScopeId of the requested {@link Account}. * @param accountId * The id of the requested {@link Account} * @param account * The modified Account whose attributed need to be updated. * @return The updated account. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "accountUpdate", value = "Update an Account", // notes = "Updates a new Account based on the information provided in the Account parameter.", // response = Account.class) @PUT @Path("{accountId}") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Account update( @ApiParam(value = "The ScopeId of the requested Account.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, // @ApiParam(value = "The id of the requested Account", required = true) @PathParam("accountId") EntityId accountId, // @ApiParam(value = "The modified Account whose attributes needs to be updated", required = true) Account account) throws Exception { account.setScopeId(scopeId); account.setId(accountId); return accountService.update(account); }
/** * Deletes the Account specified by the "accountId" path parameter. * * @param scopeId * The ScopeId of the requested {@link Account}. * @param accountId * The id of the Account to be deleted. * @return HTTP 200 if operation has completed successfully. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "accountDelete", value = "Delete an Account", // notes = "Deletes the Account specified by the \"accountId\" path parameter.") @DELETE @Path("{accountId}") public Response deleteAccount( @ApiParam(value = "The ScopeId of the Account to delete.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, // @ApiParam(value = "The id of the Account to be deleted", required = true) @PathParam("accountId") EntityId accountId) throws Exception { accountService.delete(scopeId, accountId); return returnOk(); }
AccountListResult childAccounts = accountService.query(childAccountsQuery);
@When("I change the current account expiration date to \"(.+)\"") public void changeCurrentAccountExpirationDate(String newExpiration) throws Exception { Account currAcc = (Account) stepData.get("LastAccount"); Date newDate = parseDateString(newExpiration); try { primeException(); currAcc.setExpirationDate(newDate); Account tmpAcc = accountService.update(currAcc); stepData.put("LastAccount", tmpAcc); } catch (KapuaException e) { verifyException(e); } }
@Override public MessageInfo getInfo(KapuaId scopeId) throws ConfigurationException { Account account = null; if (scopeId != null) { try { account = KapuaSecurityUtils.doPrivileged(() -> accountService.find(scopeId)); } catch (Exception exc) { throw new ConfigurationException("Cannot get account information", exc); } } return new MessageInfo(account); }
public KapuaId getScopeId() throws KapuaException { return KapuaSecurityUtils.doPrivileged(() -> accountService.findByName(scope).getId()); }
Account createAccount(String name, String orgName, String orgEmail) throws KapuaException { configureAccountService(ROOT_SCOPE_ID, SYS_ID); AccountCreator accountCreator = accountFactory.newCreator(ROOT_SCOPE_ID, name); accountCreator.setOrganizationName(orgName); accountCreator.setOrganizationEmail(orgEmail); return accountService.create(accountCreator); }
AccountListResult childAccounts = accountService.query(childAccountsQuery);
account = KapuaSecurityUtils.doPrivileged(() -> accountService.find(accessToken.getScopeId())); } catch (Exception e) {
@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); }); }
/** * Create account in privileged mode as kapua-sys user. * Account is created in scope specified by scopeId in testAccount parameter. * This is not accountId, but account under which it is created. AccountId itself * is created automatically. * * @param testAccount basic data about account * @return Kapua Account object */ private Account createAccount(TestAccount testAccount) throws Exception { List<Account> accountList = new ArrayList<>(); KapuaSecurityUtils.doPrivileged(() -> { primeException(); try { Account account = accountService.create(accountCreatorCreator(testAccount.getName(), testAccount.getScopeId(), testAccount.getExpirationDate())); accountList.add(account); } catch (KapuaException ke) { verifyException(ke); } return null; }); return accountList.size() == 1 ? accountList.get(0) : null; }
Account account = KapuaSecurityUtils.doPrivileged(() -> ACCOUNT_SERVICE.find(permission.getTargetScopeId()));
@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); }); }
Account account = accountService.create(accountCreator);
Account account = KapuaSecurityUtils.doPrivileged(() -> ACCOUNT_SERVICE.find(permission.getTargetScopeId()));