@Override public Account create(AccountCreator creator) throws KapuaException { // TODO Auto-generated method stub AccountMock account = new AccountMock(creator.getScopeId(), creator.getName()); return account; }
ArgumentValidator.notNull(accountCreator.getScopeId(), "accountCreator.scopeId"); ArgumentValidator.notEmptyOrNull(accountCreator.getName(), "accountCreator.name"); ArgumentValidator.notEmptyOrNull(accountCreator.getOrganizationName(), "accountCreator.organizationName"); authorizationService.checkPermission(permissionFactory.newPermission(AccountDomains.ACCOUNT_DOMAIN, Actions.write, accountCreator.getScopeId())); if (allowedChildEntities(accountCreator.getScopeId()) <= 0) { throw new KapuaMaxNumberOfItemsReachedException("Accounts"); if (findById(accountCreator.getScopeId()) == null) { throw new KapuaIllegalArgumentException("scopeId", "parent account does not exist: " + accountCreator.getScopeId() + "::"); AccountQuery query = new AccountQueryImpl(accountCreator.getScopeId()); query.setPredicate(new AttributePredicateImpl<>(AccountAttributes.NAME, accountCreator.getName())); if (count(query) > 0) { Account parentAccount = KapuaSecurityUtils.doPrivileged(() -> find(accountCreator.getScopeId())); if (parentAccount != null && parentAccount.getExpirationDate() != null) { String parentAccountPath = AccountDAO.find(em, null, accountCreator.getScopeId()).getParentAccountPath() + "/" + account.getId(); account.setParentAccountPath(parentAccountPath); return AccountDAO.update(em, account);
ArgumentValidator.notNull(accountCreator.getScopeId(), "accountCreator.scopeId"); ArgumentValidator.notEmptyOrNull(accountCreator.getName(), "accountCreator.name"); ArgumentValidator.notEmptyOrNull(accountCreator.getOrganizationName(), "accountCreator.organizationName"); authorizationService.checkPermission(permissionFactory.newPermission(AccountDomains.ACCOUNT_DOMAIN, Actions.write, accountCreator.getScopeId())); if (allowedChildEntities(accountCreator.getScopeId()) <= 0) { throw new KapuaMaxNumberOfItemsReachedException("Accounts"); if (findById(accountCreator.getScopeId()) == null) { throw new KapuaIllegalArgumentException("scopeId", "parent account does not exist: " + accountCreator.getScopeId() + "::"); AccountQuery query = new AccountQueryImpl(accountCreator.getScopeId()); query.setPredicate(new AttributePredicateImpl<>(AccountAttributes.NAME, accountCreator.getName())); if (count(query) > 0) { Account parentAccount = KapuaSecurityUtils.doPrivileged(() -> find(accountCreator.getScopeId())); if (parentAccount != null && parentAccount.getExpirationDate() != null) { String parentAccountPath = AccountDAO.find(em, null, accountCreator.getScopeId()).getParentAccountPath() + "/" + account.getId(); account.setParentAccountPath(parentAccountPath); return AccountDAO.update(em, account);
/** * Creates and return new Account * * @param em * @param accountCreator * @return * @throws KapuaException */ public static Account create(EntityManager em, AccountCreator accountCreator) throws KapuaException { // // Create Account OrganizationImpl organizationImpl = new OrganizationImpl(); organizationImpl.setName(accountCreator.getOrganizationName()); organizationImpl.setPersonName(accountCreator.getOrganizationPersonName()); organizationImpl.setEmail(accountCreator.getOrganizationEmail()); organizationImpl.setPhoneNumber(accountCreator.getOrganizationPhoneNumber()); organizationImpl.setAddressLine1(accountCreator.getOrganizationAddressLine1()); organizationImpl.setAddressLine2(accountCreator.getOrganizationAddressLine2()); organizationImpl.setCity(accountCreator.getOrganizationCity()); organizationImpl.setZipPostCode(accountCreator.getOrganizationZipPostCode()); organizationImpl.setStateProvinceCounty(accountCreator.getOrganizationStateProvinceCounty()); organizationImpl.setCountry(accountCreator.getOrganizationCountry()); AccountImpl accountImpl = new AccountImpl(accountCreator.getScopeId(), accountCreator.getName()); accountImpl.setOrganization(organizationImpl); accountImpl.setExpirationDate(accountCreator.getExpirationDate()); return ServiceDAO.create(em, accountImpl); }
/** * Creates and return new Account * * @param em * @param accountCreator * @return * @throws KapuaException */ public static Account create(EntityManager em, AccountCreator accountCreator) throws KapuaException { // // Create Account OrganizationImpl organizationImpl = new OrganizationImpl(); organizationImpl.setName(accountCreator.getOrganizationName()); organizationImpl.setPersonName(accountCreator.getOrganizationPersonName()); organizationImpl.setEmail(accountCreator.getOrganizationEmail()); organizationImpl.setPhoneNumber(accountCreator.getOrganizationPhoneNumber()); organizationImpl.setAddressLine1(accountCreator.getOrganizationAddressLine1()); organizationImpl.setAddressLine2(accountCreator.getOrganizationAddressLine2()); organizationImpl.setCity(accountCreator.getOrganizationCity()); organizationImpl.setZipPostCode(accountCreator.getOrganizationZipPostCode()); organizationImpl.setStateProvinceCounty(accountCreator.getOrganizationStateProvinceCounty()); organizationImpl.setCountry(accountCreator.getOrganizationCountry()); AccountImpl accountImpl = new AccountImpl(accountCreator.getScopeId(), accountCreator.getName()); accountImpl.setOrganization(organizationImpl); accountImpl.setExpirationDate(accountCreator.getExpirationDate()); return ServiceDAO.create(em, accountImpl); }