Skip to content

Commit

Permalink
Add active only validation for Token Definition and Token (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih authored Feb 22, 2025
1 parent 3fed819 commit 987c198
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion base/src/org/spin/model/MADToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected boolean beforeSave(boolean newRecord) {
if(newRecord
|| is_ValueChanged(COLUMNNAME_AD_Role_ID)) {
if(getAD_Role_ID() > 0) {
Optional.ofNullable(MRole.get(getCtx(), getAD_Role_ID())).ifPresent(role -> setClientOrg(role));
Optional.of(MRole.get(getCtx(), getAD_Role_ID())).ifPresent(this::setClientOrg);
}
}
return super.beforeSave(newRecord);
Expand Down
12 changes: 9 additions & 3 deletions base/src/org/spin/model/MADTokenDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.spin.model;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -69,8 +71,10 @@ public static MADTokenDefinition getById(Properties ctx, int definitionId, Strin

definition = new Query(ctx , Table_Name , COLUMNNAME_AD_TokenDefinition_ID + "=?" , trxName)
.setParameters(definitionId)
.setOnlyActiveRecords(true)
.first();
if (definition != null && definition.get_ID() > 0) {
definition.set_TrxName(null);
int clientId = Env.getAD_Client_ID(ctx);
String key = clientId + "#" + definition.getValue();
definitionCacheValues.put(key, definition);
Expand Down Expand Up @@ -101,10 +105,12 @@ public static MADTokenDefinition getByTokenType(Properties ctx, String tokenType

definition = new Query(ctx, Table_Name , COLUMNNAME_TokenType + "=? AND AD_Client_ID IN(0, ?)", trxName)
.setParameters(tokenType, clientId)
.setOnlyActiveRecords(true)
.setOrderBy(COLUMNNAME_AD_Client_ID + " DESC")
.first();

if (definition != null && definition.get_ID() > 0) {
definition.set_TrxName(null);
definitionCacheValues.put(key, definition);
definitionCacheIds.put(definition.get_ID() , definition);
}
Expand All @@ -123,19 +129,19 @@ public static List<MADTokenDefinition> getAll(Properties ctx, boolean resetCache
if (resetCache || definitionCacheIds.size() > 0 ) {
definitionList = new Query(Env.getCtx(), Table_Name, null , trxName)
.setClient_ID()
.setOnlyActiveRecords(true)
.setOrderBy(COLUMNNAME_Name)
.list();
definitionList.stream().forEach(definition -> {
int clientId = Env.getAD_Client_ID(ctx);
String key = clientId + "#" + definition.getValue();
definition.set_TrxName(null);
definitionCacheIds.put(definition.getAD_TokenDefinition_ID(), definition);
definitionCacheValues.put(key, definition);
});
return definitionList;
}
definitionList = definitionCacheIds.entrySet().stream()
.map(activity -> activity.getValue())
.collect(Collectors.toList());
definitionList = new ArrayList<>(definitionCacheIds.values());
return definitionList;
}

Expand Down
1 change: 0 additions & 1 deletion base/src/org/spin/util/TokenGeneratorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ private void loadClass(String tokenType) throws Exception {
// Not yet implemented
if (clazz == null) {
logger.log(Level.SEVERE, "Class not found, Using Standard Class");
generator = null;
throw new Exception("Class for connection not found");
}
//
Expand Down

0 comments on commit 987c198

Please sign in to comment.