Refs #21013: Migrate accounting-manager to postgresql persistence

Updated GetSpaces
This commit is contained in:
Giancarlo Panichi 2021-04-01 10:14:06 +02:00
parent ef12d844c1
commit 72ea4d1314
1 changed files with 13 additions and 18 deletions

View File

@ -16,10 +16,8 @@ import org.slf4j.LoggerFactory;
* *
* *
*/ */
public class AccountingCommandGetSpaces implements public class AccountingCommandGetSpaces implements AccountingCommand<Spaces> {
AccountingCommand<Spaces> { private static final Logger logger = LoggerFactory.getLogger(AccountingCommandGetSpaces.class);
private static final Logger logger = LoggerFactory
.getLogger(AccountingCommandGetSpaces.class);
public AccountingCommandGetSpaces() { public AccountingCommandGetSpaces() {
} }
@ -29,32 +27,29 @@ public class AccountingCommandGetSpaces implements
try { try {
logger.debug("getSpaces()"); logger.debug("getSpaces()");
SortedSet<String> keys = null; SortedSet<String> keys = null;
AccountingPersistenceQuery apq = AccountingPersistenceQueryFactory AccountingPersistenceQuery apq = AccountingPersistenceQueryFactory.getInstance();
.getInstance();
keys = apq.getSpaceProvidersIds(); keys = apq.getSpaceProvidersIds();
logger.debug("AccountingPersistenceQuery.getSpaces: " + keys); logger.debug("AccountingPersistenceQuery.getSpaces: " + keys);
if (keys == null || keys.isEmpty()) {
return null;
}
ArrayList<String> spaceList = new ArrayList<>(); ArrayList<String> spaceList = new ArrayList<>();
if (keys == null || keys.isEmpty()) {
logger.error("Spaces have not keys: {}", keys);
} else {
for (String key : keys) { for (String key : keys) {
if (key != null && !key.isEmpty()) { if (key != null && !key.isEmpty()) {
spaceList.add(key); spaceList.add(key);
} }
} }
}
Spaces categories = new Spaces(spaceList); Spaces categories = new Spaces(spaceList);
logger.debug("Spaces:" + categories); logger.debug("Spaces:" + categories);
return categories; return categories;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error in AccountingCommandGetSpaces(): " logger.error("Error in AccountingCommandGetSpaces(): {}", e.getLocalizedMessage(), e);
+ e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException("No spaces available!"); throw new ServiceException("No spaces available!");
} }