Skip to content

Commit

Permalink
updates default data for keysDao
Browse files Browse the repository at this point in the history
  • Loading branch information
nicol committed Sep 11, 2023
1 parent 0aa9b74 commit 716d657
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/main/java/org/beta/RedisDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ public void commandSucceeded(CommandSucceededEvent event) {
connection = redisClient.connect();
syncCommands = connection.sync();




saveCollection(new MagicCollection("Library"));
initDefaultData();

}

Expand Down Expand Up @@ -357,6 +354,7 @@ public int saveOrUpdateContact(Contact c) throws SQLException {
if(c.getId()<0)
c.setId(incr(Contact.class).intValue());


syncCommands.set(key(c), serialiser.toJson(c));

return c.getId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.magic.api.interfaces.abstracts.extra;


import java.sql.SQLException;

import org.magic.api.beans.Announce;
import org.magic.api.beans.MagicCard;
import org.magic.api.beans.MagicCardAlert;
Expand All @@ -15,6 +17,7 @@
import org.magic.api.beans.technical.GedEntry;
import org.magic.api.interfaces.MTGSerializable;
import org.magic.api.interfaces.abstracts.AbstractMagicDAO;
import org.magic.services.MTGConstants;

public abstract class AbstractKeyValueDao extends AbstractMagicDAO {

Expand All @@ -36,7 +39,28 @@ public boolean isSQL() {
protected static final String KEY_NEWS ="news";
protected static final String KEY_GED ="ged";


@Override
public void init() throws SQLException {
initDefaultData();

}


protected void initDefaultData() throws SQLException
{

if(listCollections().isEmpty()) {
for(String s : MTGConstants.getDefaultCollectionsNames())
saveCollection(s);
}

if(getContactById(1)==null)
saveOrUpdateContact(MTGConstants.DEFAULT_CONTACT);

}


protected <T extends MTGSerializable> String key(GedEntry<T> gedItem) {
return KEY_GED+SEPARATOR+gedItem.getClasse().getSimpleName()+SEPARATOR+gedItem.getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
import org.magic.api.pool.impl.NoPool;
import org.magic.services.MTGControler;
import org.magic.services.PluginRegistry;
import org.magic.services.SQLTools;
import org.magic.services.TechnicalServiceManager;
import org.magic.services.tools.CryptoUtils;
import org.magic.services.tools.IDGenerator;
import org.magic.services.tools.ImageTools;
import org.magic.services.tools.MTG;
import org.magic.services.tools.SQLTools;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -232,11 +232,7 @@ private boolean createDB() throws SQLException {

postCreation(stat);

logger.debug("populate default datas");
stat.executeUpdate(hlper.insertDefaultCollections());
stat.executeUpdate(hlper.insertMainContact());




createIndex(stat);

Expand Down Expand Up @@ -472,7 +468,9 @@ public void deleteAnnounce(Announce a) throws SQLException {

protected void postCreation(Statement stat) throws SQLException
{
//do nothing
logger.debug("populate default datas");
stat.executeUpdate(hlper.insertDefaultCollections());
stat.executeUpdate(hlper.insertMainContact());
}


Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/magic/main/ChangeDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.magic.main;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JPanel;

import org.magic.api.interfaces.MTGDao;
import org.magic.gui.abstracts.MTGUIComponent;
import org.magic.services.MTGConstants;
import org.magic.services.MTGControler;
import org.magic.services.tools.MTG;
import org.magic.services.tools.UITools;

public class ChangeDAO {
public static void main(String[] args)
{
MTGControler.getInstance().loadAccountsConfiguration();

var cbo = UITools.createComboboxPlugins(MTGDao.class, true);
var btnValid = new JButton("Validate");

var pane = new JPanel();
pane.setLayout(new BorderLayout());
pane.add(cbo,BorderLayout.CENTER);
pane.add(btnValid,BorderLayout.SOUTH);


var diag = MTGUIComponent.createJDialog(MTGUIComponent.build(pane, "Change DAO", MTGConstants.ICON_TAB_DAO), false, false);
diag.setVisible(true);


btnValid.addActionListener(al->{

var selectedProvider = (MTGDao)cbo.getSelectedItem();
selectedProvider.enable(true);
MTGControler.getInstance().setProperty(selectedProvider, selectedProvider.isEnable());

MTG.listPlugins(MTGDao.class).stream().filter(p->p!=selectedProvider).forEach(p->{
p.enable(false);
MTGControler.getInstance().setProperty(p, p.isEnable());
});


System.exit(0);

});



}

}
17 changes: 17 additions & 0 deletions src/main/java/org/magic/services/MTGConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jdesktop.swingx.util.PaintUtils;
import org.magic.api.beans.MagicCollection;
import org.magic.api.beans.MagicEdition;
import org.magic.api.beans.shop.Contact;
import org.magic.services.providers.IconSetProvider;

import freemarker.template.Configuration;
Expand All @@ -46,6 +47,22 @@ public static String[] getDefaultCollectionsNames() {
return DEFAULT_COLLECTIONS_NAMES;
}

public static final Contact DEFAULT_CONTACT;

static {
DEFAULT_CONTACT = new Contact();
DEFAULT_CONTACT.setId(1);
DEFAULT_CONTACT.setName("MTG");
DEFAULT_CONTACT.setLastName("Companion");
DEFAULT_CONTACT.setTelephone("123456789");
DEFAULT_CONTACT.setAddress("Somewhere");
DEFAULT_CONTACT.setCity("In the middle of nowhere");
DEFAULT_CONTACT.setWebsite("https://www.mtgcompanion.org");
DEFAULT_CONTACT.setEmail("[email protected]");
DEFAULT_CONTACT.setActive(true);
DEFAULT_CONTACT.setEmailAccept(true);
}


//CONFIG FILES CONSTANTS
public static final String MTG_DESKTOP_VERSION_FILE = "/version";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.magic.services;
package org.magic.services.tools;

import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
Expand All @@ -9,6 +9,8 @@
import org.jooq.conf.StatementType;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.magic.services.MTGConstants;
import org.magic.services.TransactionService;
import org.magic.services.logging.MTGLogger;


Expand Down

0 comments on commit 716d657

Please sign in to comment.