Skip to content

Commit

Permalink
Merge pull request #4191 from Coduz/feat-relativeFinderFindDirectParent
Browse files Browse the repository at this point in the history
✨ [Account] Addded `findParentId` to `AccountRelativeFinder`
  • Loading branch information
Coduz authored Feb 7, 2025
2 parents 004b364 + dbdb6d2 commit 3d48c52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2022, 2025 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,8 +15,10 @@
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.KapuaService;
import org.eclipse.kapua.service.account.Account;
import org.eclipse.kapua.service.account.AccountListResult;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Optional;

Expand All @@ -32,13 +34,25 @@ public interface AccountRelativeFinder extends KapuaService {
* @param targetScopeId - nullable target scope id
* @return the list of child accounts
* @throws KapuaException
* @since 2.0.0
*/
AccountListResult findChildren(KapuaId scopeId, Optional<KapuaId> targetScopeId) throws KapuaException;

/**
* @param accountId The id of the account to lookup
* @return The list of parent ids for the target account
* @throws KapuaException
* @since 2.1.0
*/
List<KapuaId> findParentIds(KapuaId accountId) throws KapuaException;

/**
* Gets the {@link Account#getScopeId()} which is the parent {@link Account} of the given {@link Account#getId()}
*
* @param accountId The {@link Account#getId()} to search for parent
* @return The parent {@link Account#getId()}
* @throws KapuaException
* @since 2.1.0
*/
KapuaId findParentId(@NotNull KapuaId accountId) throws KapuaException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;

import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.configuration.AccountRelativeFinder;
import org.eclipse.kapua.commons.model.id.KapuaEid;
Expand Down Expand Up @@ -85,4 +86,15 @@ public List<KapuaId> findParentIds(KapuaId accountId) throws KapuaException {

return parentAccountIds;
}

@Override
public KapuaId findParentId(KapuaId accountId) throws KapuaException {
Account account = KapuaSecurityUtils.doPrivileged(() -> accountService.find(accountId));

if(account == null){
throw new KapuaEntityNotFoundException(Account.TYPE, accountId);
}

return account.getScopeId();
}
}

0 comments on commit 3d48c52

Please sign in to comment.