/** * 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); }
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); }
/** * 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 = accountService.create(accountCreator);