Search in sources :

Example 1 with XmlFile

use of com.qlangtech.tis.extension.impl.XmlFile in project plugins by qlangtech.

the class TestDefaultDataxProcessor method testSaveProcess.

public void testSaveProcess() {
    final String appName = "test" + RandomStringUtils.randomAlphanumeric(2);
    try {
        DefaultDataxProcessor dataxProcessor = new DefaultDataxProcessor();
        IDataxProcessor.TableAlias tabAlias = new IDataxProcessor.TableAlias();
        tabAlias.setFrom("customer_order_relation");
        tabAlias.setTo("customer_order_relation1");
        List<IDataxProcessor.TableAlias> tableMaps = Lists.newArrayList(tabAlias);
        dataxProcessor.setTableMaps(tableMaps);
        dataxProcessor.globalCfg = "datax-global-config";
        dataxProcessor.dptId = "356";
        dataxProcessor.recept = "小明";
        IAppSource.save(null, appName, dataxProcessor);
        DefaultDataxProcessor loadDataxProcessor = IAppSource.load(appName);
        assertNotNull("loadDataxProcessor can not be null", loadDataxProcessor);
        assertEquals(dataxProcessor.globalCfg, loadDataxProcessor.globalCfg);
        assertEquals(dataxProcessor.dptId, loadDataxProcessor.dptId);
        assertEquals(dataxProcessor.recept, loadDataxProcessor.recept);
        Map<String, IDataxProcessor.TableAlias> tabAlias1 = loadDataxProcessor.getTabAlias();
        assertEquals(1, tabAlias1.size());
        for (Map.Entry<String, IDataxProcessor.TableAlias> entry : tabAlias1.entrySet()) {
            assertEquals(tabAlias.getFrom(), entry.getKey());
            assertEquals(tabAlias.getFrom(), entry.getValue().getFrom());
            assertEquals(tabAlias.getTo(), entry.getValue().getTo());
        }
    } finally {
        try {
            KeyedPluginStore.AppKey appKey = new KeyedPluginStore.AppKey(null, false, appName, IAppSource.class);
            XmlFile storeFile = appKey.getSotreFile();
            FileUtils.forceDelete(storeFile.getFile().getParentFile());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : XmlFile(com.qlangtech.tis.extension.impl.XmlFile) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) IOException(java.io.IOException) Map(java.util.Map)

Example 2 with XmlFile

use of com.qlangtech.tis.extension.impl.XmlFile in project tis by qlangtech.

the class TIS method loadGlobalComponent.

public GlobalComponent loadGlobalComponent() {
    if (globalComponent == null) {
        try {
            File globalConfig = getGlobalConfigFile();
            if (!globalConfig.exists()) {
                // 不存在的话
                return new GlobalComponent();
            }
            globalComponent = (GlobalComponent) (new XmlFile(globalConfig).read());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return globalComponent;
}
Also used : XmlFile(com.qlangtech.tis.extension.impl.XmlFile) GlobalComponent(com.qlangtech.tis.component.GlobalComponent) IOException(java.io.IOException) XmlFile(com.qlangtech.tis.extension.impl.XmlFile) File(java.io.File)

Example 3 with XmlFile

use of com.qlangtech.tis.extension.impl.XmlFile in project tis by qlangtech.

the class UpdateCenter method load.

/**
 * Loads the data from the disk into this object.
 */
public synchronized void load() throws IOException {
    XmlFile file = getConfigFile();
    if (file.exists()) {
        try {
            sites.replaceBy(((PersistedList) file.unmarshal(sites)).toList());
        } catch (IOException e) {
            LOGGER.warn("Failed to load " + file, e);
        }
        boolean defaultSiteExists = false;
        for (UpdateSite site : sites) {
            // replace the legacy site with the new site
            if (site.isLegacyDefault()) {
                sites.remove(site);
            } else if (ID_DEFAULT.equals(site.getId())) {
                defaultSiteExists = true;
            }
        }
        if (!defaultSiteExists) {
            sites.add(createDefaultUpdateSite());
        }
    } else {
        if (sites.isEmpty()) {
            // If there aren't already any UpdateSources, add the default one.
            // to maintain compatibility with existing UpdateCenterConfiguration, create the default one as specified by UpdateCenterConfiguration
            sites.add(createDefaultUpdateSite());
        }
    }
    siteDataLoading = false;
}
Also used : XmlFile(com.qlangtech.tis.extension.impl.XmlFile) IOException(java.io.IOException)

Example 4 with XmlFile

use of com.qlangtech.tis.extension.impl.XmlFile in project tis by qlangtech.

the class TIS method saveComponent.

public void saveComponent(GlobalComponent gloablComponent) {
    try {
        File gloabl = getGlobalConfigFile();
        (new XmlFile(gloabl)).write(gloablComponent, Collections.emptySet());
        this.globalComponent = null;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : XmlFile(com.qlangtech.tis.extension.impl.XmlFile) IOException(java.io.IOException) XmlFile(com.qlangtech.tis.extension.impl.XmlFile) File(java.io.File)

Example 5 with XmlFile

use of com.qlangtech.tis.extension.impl.XmlFile in project tis by qlangtech.

the class TIS method loadIncrComponentUsedPlugin.

/**
 * 取得增量模块需要用到的plugin名称
 *
 * @param incrPluginConfigSet 增量相关的插件配置集合
 * @return
 */
public static Set<XStream2.PluginMeta> loadIncrComponentUsedPlugin(String collection, List<File> incrPluginConfigSet, boolean clearThreadholder) {
    try {
        synchronized (RobustReflectionConverter.usedPluginInfo) {
            if (clearThreadholder) {
                RobustReflectionConverter.usedPluginInfo.remove();
            }
            for (File incrConfig : incrPluginConfigSet) {
                if (!incrConfig.exists()) {
                    throw new IllegalStateException("file not exist,path:" + incrConfig.getAbsolutePath());
                }
                XmlFile xmlFile = new XmlFile(new XStream2PluginInfoReader(XmlFile.DEFAULT_DRIVER), incrConfig);
                xmlFile.read();
            }
            return RobustReflectionConverter.usedPluginInfo.get();
        }
    } catch (IOException e) {
        throw new RuntimeException("collection:" + collection + " relevant configs:" + incrPluginConfigSet.stream().map((f) -> f.getAbsolutePath()).collect(Collectors.joining(",")), e);
    }
}
Also used : XmlFile(com.qlangtech.tis.extension.impl.XmlFile) IOException(java.io.IOException) XmlFile(com.qlangtech.tis.extension.impl.XmlFile) File(java.io.File)

Aggregations

XmlFile (com.qlangtech.tis.extension.impl.XmlFile)9 IOException (java.io.IOException)7 File (java.io.File)4 GlobalComponent (com.qlangtech.tis.component.GlobalComponent)1 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)1 KeyedPluginStore (com.qlangtech.tis.plugin.KeyedPluginStore)1 XStream2PluginInfoReader (com.qlangtech.tis.util.XStream2PluginInfoReader)1 Map (java.util.Map)1