Skip to content

Commit

Permalink
add attribute for digital card. Please update with script
Browse files Browse the repository at this point in the history
update-52.groovy
  • Loading branch information
nicol authored and nicol committed Nov 30, 2024
1 parent 4a69b85 commit 6323956
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 31 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-jdbc</artifactId>
<version>465</version>
<version>466</version>
</dependency>
<dependency>
<groupId>org.firebirdsql.jdbc</groupId>
Expand Down Expand Up @@ -374,7 +374,7 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.47.0.0</version>
<version>3.47.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -598,7 +598,7 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.18.1</version>
<version>1.18.2</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/magic/api/beans/MTGCardStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
public class MTGCardStock extends AbstractStockItem<MTGCard> {

private static final long serialVersionUID = 1L;

private boolean digital;



public MTGCardStock(MTGCard c) {
super();
id = -1L;
Expand All @@ -18,6 +21,15 @@ public MTGCardStock(MTGCard c) {
}
}

public void setDigital(boolean digitalcard) {
this.digital = digitalcard;
}

public boolean isDigital() {
return digital;
}


public MTGCardStock() {
id=-1L;
tiersAppIds= new HashMap<>();
Expand All @@ -31,6 +43,10 @@ public void setProduct(MTGCard c) {
edition= c.getEdition();
product.setTypeProduct(EnumItems.CARD);
product.setEdition(c.getEdition());

setDigital(c.isOnlineOnly());


if(c.getFinishes().size()==1 && c.getFinishes().contains(EnumFinishes.FOIL))
setFoil(true);

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/magic/api/beans/enums/EnumCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public enum EnumCondition implements MTGIconable{
PROXY("PX",new Color(255,102,255)),
DAMAGED ("DM",new Color(153,76,0)),
SEALED ("SD",new Color(0,153,153)),
OPENED ("OP",new Color(0,102,102)),
ONLINE("ONL",new Color(255,0,127));
OPENED ("OP",new Color(0,102,102));


private String codename;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/magic/api/exports/impl/MTGProTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public List<MTGCardStock> importStock(String content) throws IOException {
{
var mcs = MTGControler.getInstance().getDefaultStock();
mcs.setProduct(mc);
mcs.setCondition(EnumCondition.ONLINE);
mcs.setCondition(EnumCondition.MINT);
mcs.setDigital(true);
mcs.setQte(Integer.parseInt(m.group(4)));
mcs.setLanguage(MTGControler.getInstance().getLocale().getLanguage());
ret.add(mcs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ public void saveOrUpdateCardStock(MTGCardStock state) throws SQLException {

if (state.getId() < 0) {
logger.debug("save stock {}",state);
try (var c = pool.getConnection(); var pst = c.prepareStatement( "insert into stocks ( conditions,foil,signedcard,langage,qte,comments,idmc,collection,mcard,altered,price,grading,tiersAppIds,etched,idMe,dateUpdate,name) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS)) {
try (var c = pool.getConnection(); var pst = c.prepareStatement( "insert into stocks ( conditions,foil,signedcard,langage,qte,comments,idmc,collection,mcard,altered,price,grading,tiersAppIds,etched,idMe,dateUpdate,name,digital) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS)) {
pst.setString(1, state.getCondition().name());
pst.setBoolean(2, state.isFoil());
pst.setBoolean(3, state.isSigned());
Expand All @@ -1614,6 +1614,7 @@ public void saveOrUpdateCardStock(MTGCardStock state) throws SQLException {
pst.setString(15, state.getProduct().getEdition().getId());
pst.setTimestamp(16, new Timestamp(new java.util.Date().getTime()));
pst.setString(17, state.getProduct().getName());
pst.setBoolean(18, state.isDigital());
executeUpdate(pst,false);
state.setId(getGeneratedKey(pst));
state.setDateUpdate(new java.util.Date());
Expand All @@ -1623,7 +1624,7 @@ public void saveOrUpdateCardStock(MTGCardStock state) throws SQLException {
} else {
logger.debug("update Stock {}",state);
try (var c = pool.getConnection(); var pst = c.prepareStatement(
"update stocks set comments=?, conditions=?, foil=?,signedcard=?,langage=?, qte=? ,altered=?,price=?,idmc=?,collection=?,grading=?,tiersAppIds=?,etched=?, mcard=?, idMe=?, dateUpdate=?, name=? where idstock=?")) {
"update stocks set comments=?, conditions=?, foil=?,signedcard=?,langage=?, qte=? ,altered=?,price=?,idmc=?,collection=?,grading=?,tiersAppIds=?,etched=?, mcard=?, idMe=?, dateUpdate=?, name=?, digital=? where idstock=?")) {
pst.setString(1, state.getComment());
pst.setString(2, state.getCondition().name());
pst.setBoolean(3, state.isFoil());
Expand All @@ -1641,7 +1642,8 @@ public void saveOrUpdateCardStock(MTGCardStock state) throws SQLException {
pst.setString(15, state.getProduct().getEdition().getId());
pst.setTimestamp(16, new Timestamp(new java.util.Date().getTime()));
pst.setString(17, state.getProduct().getName());
pst.setLong(18, state.getId());
pst.setBoolean(18, state.isDigital());
pst.setLong(19, state.getId());
executeUpdate(pst,false);
state.setDateUpdate(new java.util.Date());
} catch (Exception e) {
Expand Down Expand Up @@ -2001,7 +2003,7 @@ private MTGCardStock readStock(ResultSet rs) throws SQLException
state.setGrade(readGrading(rs));
state.setTiersAppIds(readTiersApps(rs));
state.setEtched(rs.getBoolean("etched"));

state.setDigital(rs.getBoolean("digital"));
if(state.getTiersAppIds()==null)
state.setTiersAppIds(new HashMap<>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class DefaultStockEditorDialog extends JDialog {
private JPanel panel1;
private JLabel lblCondition;
private JComboBox<EnumCondition> cboConditions;
private JLabel digitalLabel;
private JCheckBox chkkdigital;


/**
Expand All @@ -60,9 +62,9 @@ public DefaultStockEditorDialog() {
//
var gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[] { 0, 109, 0, 0, 0 };
gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0 };
gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 1.0E-4 };
gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0E-4 };
gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0E-4 };
mcontentPane.setLayout(gridBagLayout);

var alteredLabel = new JLabel("Altered:");
Expand Down Expand Up @@ -150,12 +152,27 @@ public DefaultStockEditorDialog() {


panel1.add(lblQtyValue);

digitalLabel = new JLabel("Digital :");
GridBagConstraints gbc_digitalLabel = new GridBagConstraints();
gbc_digitalLabel.insets = new Insets(0, 0, 5, 5);
gbc_digitalLabel.gridx = 0;
gbc_digitalLabel.gridy = 3;
mcontentPane.add(digitalLabel, gbc_digitalLabel);

chkkdigital = new JCheckBox("");
GridBagConstraints gbc_chkkdigital = new GridBagConstraints();
gbc_chkkdigital.anchor = GridBagConstraints.WEST;
gbc_chkkdigital.insets = new Insets(0, 0, 5, 5);
gbc_chkkdigital.gridx = 1;
gbc_chkkdigital.gridy = 3;
mcontentPane.add(chkkdigital, gbc_chkkdigital);

var languageLabel = new JLabel("Language:");
var labelGbc2 = new GridBagConstraints();
labelGbc2.insets = new Insets(5, 5, 5, 5);
labelGbc2.gridx = 0;
labelGbc2.gridy = 3;
labelGbc2.gridy = 4;
mcontentPane.add(languageLabel, labelGbc2);

languageJTextField = new JTextField();
Expand All @@ -164,7 +181,7 @@ public DefaultStockEditorDialog() {
componentGbc2.insets = new Insets(5, 0, 5, 0);
componentGbc2.fill = GridBagConstraints.HORIZONTAL;
componentGbc2.gridx = 1;
componentGbc2.gridy = 3;
componentGbc2.gridy = 4;
mcontentPane.add(languageJTextField, componentGbc2);

lblCondition = new JLabel("Condition :");
Expand All @@ -173,7 +190,7 @@ public DefaultStockEditorDialog() {
gbclblCondition.fill = GridBagConstraints.VERTICAL;
gbclblCondition.insets = new Insets(0, 0, 5, 5);
gbclblCondition.gridx = 0;
gbclblCondition.gridy = 4;
gbclblCondition.gridy = 5;
mcontentPane.add(lblCondition, gbclblCondition);


Expand All @@ -189,18 +206,18 @@ public DefaultStockEditorDialog() {

var gbccboConditions = new GridBagConstraints();
gbccboConditions.gridwidth = 3;
gbccboConditions.insets = new Insets(0, 0, 5, 5);
gbccboConditions.insets = new Insets(0, 0, 5, 0);
gbccboConditions.fill = GridBagConstraints.HORIZONTAL;
gbccboConditions.gridx = 1;
gbccboConditions.gridy = 4;
gbccboConditions.gridy = 5;
mcontentPane.add(cboConditions, gbccboConditions);

panel = new JPanel();
var gbcpanel = new GridBagConstraints();
gbcpanel.gridwidth = 4;
gbcpanel.fill = GridBagConstraints.BOTH;
gbcpanel.gridx = 0;
gbcpanel.gridy = 5;
gbcpanel.gridy = 6;
mcontentPane.add(panel, gbcpanel);

btnSave = new JButton(MTGConstants.ICON_SAVE);
Expand Down Expand Up @@ -268,13 +285,21 @@ protected BindingGroup initDataBindings() {
signedJCheckBox, selectedProperty3);
autoBinding5.bind();
//

BeanProperty<MTGCardStock, Boolean> digitalProperty = BeanProperty.create("digital");
BeanProperty<JCheckBox, Boolean> selectedProperty4 = BeanProperty.create(CHECKBOX_PROPERTIES);
AutoBinding<MTGCardStock, Boolean, JCheckBox, Boolean> autoBinding6 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, magicCardStock, digitalProperty,chkkdigital, selectedProperty4);
autoBinding6.bind();


var bindingGroup = new BindingGroup();
bindingGroup.addBinding(autoBinding);
bindingGroup.addBinding(autoBinding1);
bindingGroup.addBinding(autoBinding2);
bindingGroup.addBinding(autoBinding3);
bindingGroup.addBinding(autoBinding4);
bindingGroup.addBinding(autoBinding5);
bindingGroup.addBinding(autoBinding6);
//
return bindingGroup;
}
Expand Down
33 changes: 21 additions & 12 deletions src/main/java/org/magic/gui/models/CardStockTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public CardStockTableModel() {
"ETCHED",
"SIGNED",
"ALTERED",
"DIGITAL",
"PRICE",
"GRADED",
"COMMENTS",
Expand All @@ -44,7 +45,7 @@ public CardStockTableModel() {

@Override
public int[] defaultHiddenColumns() {
return new int[] {0,4,10,11,12,14,17};
return new int[] {0,4,10,11,12,15,18};
}


Expand Down Expand Up @@ -91,14 +92,17 @@ public Class<?> getColumnClass(int columnIndex) {
case 12:
return Boolean.class;
case 13:
return Double.class;
return Boolean.class;

case 14:
return MTGGrading.class;
return Double.class;
case 15:
return String.class;
return MTGGrading.class;
case 16:
return Map.class;
return String.class;
case 17:
return Map.class;
case 18:
return Date.class;


Expand All @@ -111,7 +115,7 @@ public Class<?> getColumnClass(int columnIndex) {
public boolean isCellEditable(int row, int column) {

if(writable)
return !(column ==1 || column==2|| column==3 || column==4 || column==14 || column==17 );
return !(column ==1 || column==2|| column==3 || column==4 || column==15 || column==17 );
else
return false;
}
Expand Down Expand Up @@ -147,14 +151,16 @@ public Object getValueAt(int row, int column) {
case 12:
return items.get(row).isAltered();
case 13:
return UITools.roundDouble(items.get(row).getPrice());
return items.get(row).isDigital();
case 14:
return items.get(row).getGrade();
return UITools.roundDouble(items.get(row).getPrice());
case 15:
return items.get(row).getComment();
return items.get(row).getGrade();
case 16:
return items.get(row).getTiersAppIds();
return items.get(row).getComment();
case 17:
return items.get(row).getTiersAppIds();
case 18:
return items.get(row).getDateUpdate();
default:
return "";
Expand Down Expand Up @@ -190,12 +196,15 @@ public void setValueAt(Object aValue, int row, int column) {
items.get(row).setAltered(Boolean.parseBoolean(aValue.toString()));
break;
case 13:
items.get(row).setPrice(UITools.parseDouble(String.valueOf(aValue)));
items.get(row).setDigital(Boolean.parseBoolean(aValue.toString()));
break;
case 14:
items.get(row).setGrade((MTGGrading)aValue);
items.get(row).setPrice(UITools.parseDouble(String.valueOf(aValue)));
break;
case 15:
items.get(row).setGrade((MTGGrading)aValue);
break;
case 16:
items.get(row).setComment(String.valueOf(aValue));
break;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/magic/services/MTGControler.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public void setDefaultStock(MTGCardStock st) {
setProperty("collections/defaultStock/condition",st.getCondition().name());
setProperty("collections/defaultStock/qty",st.getQte());
setProperty("collections/defaultStock/etched",st.isEtched());
setProperty("collections/defaultStock/digital",st.isDigital());
}


Expand All @@ -220,6 +221,7 @@ public MTGCardStock getDefaultStock() {
st.setAltered(Boolean.parseBoolean(get("collections/defaultStock/altered",FALSE)));
st.setFoil(Boolean.parseBoolean(get("collections/defaultStock/foil",FALSE)));
st.setEtched(Boolean.parseBoolean(get("collections/defaultStock/etched",FALSE)));
st.setDigital(Boolean.parseBoolean(get("collections/defaultStock/digital",FALSE)));
st.setLanguage(get("collections/defaultStock/language","English"));
st.setCondition(EnumCondition.valueOf(get("collections/defaultStock/condition","NEAR_MINT")));
st.setQte(Integer.parseInt(get("collections/defaultStock/qty","1")));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/magic/services/tools/SQLTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public String createTableStocks() {
.column("signedcard",SQLDataType.BOOLEAN)
.column("altered",SQLDataType.BOOLEAN)
.column("etched",SQLDataType.BOOLEAN)
.column("digital",SQLDataType.BOOLEAN)
.column("langage",SQLDataType.VARCHAR(20))
.column("qte",SQLDataType.INTEGER)
.column("price",SQLDataType.DECIMAL(10,2))
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/data/default-conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<altered>false</altered>
<foil>false</foil>
<oversized>false</oversized>
<digital>false</digital>
<language>English</language>
<condition>MINT</condition>
<qty>1</qty>
Expand Down
25 changes: 25 additions & 0 deletions src/main/resources/script/update-2.52.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if(dao.isSQL()) {
printf("Executing db update on " + dao.getName());
try{
dao.executeQuery("ALTER TABLE stocks ADD digital BOOLEAN");
}
catch(Exception e)
{
printf("column digital already present");
}


dao.executeQuery("UPDATE stocks SET digital = true where condition ='ONLINE'");
dao.executeQuery("UPDATE stocks SET condition = 'MINT' where condition ='ONLINE'");


printf("filling stocks columns--done");




}
else
{
printf("Your DAO is not SQL. Don't need to pass script");
}

0 comments on commit 6323956

Please sign in to comment.