-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
modules/qi-sysconfig/src/main/java/org/jpos/qi/sysconfig/SysConfigConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.jpos.qi.sysconfig; | ||
|
||
import com.vaadin.data.Converter; | ||
import com.vaadin.data.Result; | ||
import com.vaadin.data.ValueContext; | ||
import org.jpos.ee.DB; | ||
import org.jpos.ee.SysConfig; | ||
import org.jpos.ee.SysConfigManager; | ||
import org.jpos.qi.QI; | ||
|
||
public class SysConfigConverter implements Converter<SysConfig, String> { | ||
private String prefix; | ||
private boolean useValue; | ||
|
||
public SysConfigConverter () { | ||
this(null, false); | ||
} | ||
|
||
public SysConfigConverter (String prefix) { | ||
this (prefix, false); | ||
} | ||
public SysConfigConverter (String prefix, boolean useValue) { | ||
super(); | ||
this.prefix = prefix; | ||
this.useValue = useValue; | ||
} | ||
|
||
@Override | ||
public Result<String> convertToModel(SysConfig value, ValueContext context) { | ||
if (value == null) | ||
return Result.error("NULL value"); | ||
else { | ||
String id = prefix != null ? value.getId().substring(prefix.length()) : value.getId(); | ||
String modelToSave = useValue ? value.getValue() : id; | ||
return Result.ok(modelToSave); | ||
} | ||
} | ||
|
||
@Override | ||
public SysConfig convertToPresentation(String value, ValueContext context) { | ||
if (value != null) { | ||
try { | ||
return DB.exec( (db) -> { | ||
SysConfigManager mgr = new SysConfigManager(db); | ||
return mgr.getObject(value); | ||
}); | ||
} catch (Exception e) { | ||
QI.getQI().getLog().error(e); | ||
} | ||
} | ||
return null; | ||
} | ||
} |