Search in sources :

Example 6 with DefaultPropertiesPersister

use of org.springframework.util.DefaultPropertiesPersister in project phoenicis by PhoenicisOrg.

the class SettingsManager method save.

public void save() {
    Settings settings = load();
    try (OutputStream outputStream = new FileOutputStream(new File(settingsFileName))) {
        DefaultPropertiesPersister persister = new DefaultPropertiesPersister();
        persister.store(settings.getProperties(), outputStream, "Phoenicis User Settings");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DefaultPropertiesPersister(org.springframework.util.DefaultPropertiesPersister) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 7 with DefaultPropertiesPersister

use of org.springframework.util.DefaultPropertiesPersister in project phoenicis by PhoenicisOrg.

the class JavaFxSettingsManager method save.

/**
 * saves settings to settings file
 */
public void save() {
    JavaFxSettings javaFxSettings = load();
    try (OutputStream outputStream = new FileOutputStream(new File(settingsFileName))) {
        DefaultPropertiesPersister persister = new DefaultPropertiesPersister();
        persister.store(javaFxSettings.getProperties(), outputStream, "Phoenicis JavaFX User JavaFxSettings");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DefaultPropertiesPersister(org.springframework.util.DefaultPropertiesPersister) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 8 with DefaultPropertiesPersister

use of org.springframework.util.DefaultPropertiesPersister in project Clownfish by rawdog71.

the class Clownfish method init.

/**
 * Call of the "init" site
 * Init is called at the beginning of the Clownfish startup and after changing system properties
 * Checks the bootstrap flag of the application.properties and calls a bootstrap routine
 * Initializes several variables and starts Quartz job triggers
 */
@PostConstruct
public void init() {
    LOGGER.info("INIT CLOWNFISH START");
    servicestatus.setMessage("Clownfish is initializing");
    servicestatus.setOnline(false);
    if (null == authtokenlist) {
        authtokenlist = new AuthTokenList();
    }
    // read all System Properties of the property table
    if (null == propertyUtil) {
        propertyUtil = new PropertyUtil(propertylist);
    }
    if (null == cfclassLoader) {
        cfclassLoader = new CfClassLoader();
    }
    if (null == cfclassCompiler) {
        cfclassCompiler = new CfClassCompiler();
        cfclassCompiler.setClownfish(this);
        cfclassCompiler.init(cfclassLoader, propertyUtil, cfjavaService);
    }
    libloaderpath = propertyUtil.getPropertyValue("folder_libs");
    if (null == beanUtil)
        beanUtil = new BeanUtil();
    if ((!libloaderpath.isBlank()) && (null != libloaderpath))
        beanUtil.init(libloaderpath);
    mavenpath = propertyUtil.getPropertyValue("folder_maven");
    if ((!mavenpath.isBlank()) && (null != mavenpath)) {
        if (classpathUtil == null) {
            classpathUtil = new ClassPathUtil();
            classpathUtil.init(cfclassLoader);
        }
        classpathUtil.addPath(mavenpath);
    }
    if (null == mavenlist) {
        mavenlist = new MavenList();
        mavenlist.setClasspathUtil(classpathUtil);
    }
    Thread compileThread = new Thread(cfclassCompiler);
    compileThread.start();
    if (1 == bootstrap) {
        bootstrap = 0;
        try {
            AnsiConsole.systemInstall();
            System.out.println(ansi().fg(GREEN));
            System.out.println("BOOTSTRAPPING II");
            System.out.println(ansi().reset());
            Properties props = new Properties();
            String propsfile = "application.properties";
            InputStream is = new FileInputStream(propsfile);
            if (null != is) {
                props.load(is);
                props.setProperty("bootstrap", String.valueOf(bootstrap));
                File f = new File("application.properties");
                bootstrap();
                OutputStream out = new FileOutputStream(f);
                DefaultPropertiesPersister p = new DefaultPropertiesPersister();
                p.store(props, out, "Application properties");
            } else {
                LOGGER.error("application.properties file not found");
            }
        } catch (IOException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
    /* Hazelcast test */
    /*
        if (null == hazelConfig) {
            hazelConfig = new Config();
        }
        if (null == hcInstance) {
            hcInstance = Hazelcast.newHazelcastInstance(hazelConfig);
        }
        */
    Package p = FacesContext.class.getPackage();
    if (null == clownfishutil) {
        clownfishutil = new ClownfishUtil();
    }
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = null;
    if ((new File("pom.xml")).exists()) {
        try {
            model = reader.read(new FileReader("pom.xml"));
        } catch (FileNotFoundException ex) {
            LOGGER.error(ex.getMessage());
        } catch (IOException | XmlPullParserException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
    if (null != model) {
        clownfishutil.setVersion(model.getVersion()).setVersionMojarra(p.getImplementationVersion()).setVersionTomcat(ServerInfo.getServerNumber());
    } else {
        clownfishutil.setVersion(getClass().getPackage().getImplementationVersion()).setVersionMojarra(p.getImplementationVersion()).setVersionTomcat(ServerInfo.getServerNumber());
    }
    try {
        AnsiConsole.systemInstall();
        System.out.println(ansi().fg(GREEN));
        System.out.println("INIT CLOWNFISH CMS Version " + clownfishutil.getVersion() + " on Tomcat " + clownfishutil.getVersionTomcat() + " with Mojarra " + clownfishutil.getVersionMojarra());
        System.out.println(ansi().fg(RED));
        System.out.println("                               ...                                             ");
        System.out.println("                            &@@@@@@@                                           ");
        System.out.println("                          .&&%%%@%@@@@                                         ");
        System.out.println("                          %%%%%%%%&%%@                                         ");
        System.out.println("                         .%%%%%%%%#%%&                                         ");
        System.out.println("                         /%%%%%%%%%##%         &&@@.                           ");
        System.out.println("                    .,*//#############%        %#%#%@@                          ");
        System.out.println("                     #((###############       ###%#%%&@                         ");
        System.out.println("           //          #((((/(/(((((((/       (###(###&%                        ");
        System.out.println("        *((//((#/       #((((#(((((((#         (((##%##@                        ");
        System.out.println("      /(((((#(////#     .((((((((((((*         *((((###%                        ");
        System.out.println("     /(((((#((######     #(((((##((@@@@&        ((((((##                        ");
        System.out.println("    (((((((####@@&#(%     #((((####((((&@/      #(((((((*            (&@@&#     ");
        System.out.println("   /(((((((#######(((&    *((((##(((((((#@/     #(((((((/          &&%%%%&@@@,  ");
        System.out.println("  /((((((((((((((#((((&    (#((#(##((##((@@     #(#####(*       *########%%&@@@.");
        System.out.println("  /%#(((((((((((((/((((.   ###########(((#@*    ((#####(.      /#########%%%@@@@");
        System.out.println("   ,(((((((((((((((((((/   ###########((((@,   ((#######       ###########%%%@@@");
        System.out.println("    .(((((((((((((/((((*   (#########((((#@    ((######%      .##########%%%&@@@");
        System.out.println("       ,/(((((((((((((&   #(#########((((@/  .#((###((((       #########%%%%&@@@");
        System.out.println("           /((((((##(&   %(((((######(((&/  .#(((((((((.       *########%%%&&@@@");
        System.out.println("              ,//(#@   /(#(####(((##(((&.  (((((((((/           /######%%%&&@@@@");
        System.out.println("                ./* .#(########((#((*/.  *#(((((((###.           /%##%%%%@@@@@@ ");
        System.out.println("                /######((#######(    ./#######(###(#@              .&@@@@@@@%   ");
        System.out.println("               /#######%%#(((#((((@.  /@%#####(##((@#                           ");
        System.out.println("              /####%%#@& *#(((//(/(%@   *@@@@%#%&@@                             ");
        System.out.println("              %#%&&@&*    *((((///(@@&     .##/*                                ");
        System.out.println("                  ,,***,   *((/(#@@@@@,                                         ");
        System.out.println("                            *@@@@@@@@%                                          ");
        System.out.println(ansi().reset());
        // Check Consistence
        if (checkConsistency > 0) {
            consistencyUtil.checkConsistency();
        }
        // Generate Hibernate DOM Mapping
        if (null == hibernateInitializer) {
            hibernateInitializer = new HibernateInit(servicestatus, cfclassService, cfattributService, cfclasscontentService, cfattributcontentService, cflistcontentService, cfclasscontentkeywordService, cfkeywordService, dburl);
            hibernateUtil.init(hibernateInitializer);
            hibernateUtil.setHibernateInit(hibernateInit);
            Thread hibernateThread = new Thread(hibernateUtil);
            hibernateThread.start();
        /*
                hibernateUtil.generateTablesDatamodel(hibernateInit);
                // generate Relation Tables
                hibernateUtil.generateRelationsDatamodel(hibernateInit);
                */
        }
        propertylist.setClownfish(this);
        if (null == defaultUtil) {
            defaultUtil = new DefaultUtil();
        }
        if (mailUtil == null)
            mailUtil = new MailUtil(propertyUtil);
        if (pdfUtil == null)
            pdfUtil = new PDFUtil(cftemplateService, cftemplateversionService, cfsitedatasourceService, cfdatasourceService, cfsiteService, propertyUtil, templateUtil);
        // Set default values
        // 1 = Staging mode (fetch sourcecode from commited repository) <= default
        modus = STAGING;
        // 0 = Development mode (fetch sourcecode from database)
        defaultUtil.setCharacterEncoding("UTF-8").setContentType("text/html").setLocale(new Locale("de"));
        sapSupport = propertyUtil.getPropertyBoolean("sap_support", sapSupport);
        if (sapSupport) {
            if (null == sapc) {
                sapc = new SAPConnection(SAPCONNECTION, "Clownfish1");
                rpytableread = new RPY_TABLE_READ(sapc);
            }
        }
        // Override default values with system properties
        String systemContentType = propertyUtil.getPropertyValue("response_contenttype");
        String systemCharacterEncoding = propertyUtil.getPropertyValue("response_characterencoding");
        String systemLocale = propertyUtil.getPropertyValue("response_locale");
        if (!systemCharacterEncoding.isEmpty()) {
            defaultUtil.setCharacterEncoding(systemCharacterEncoding);
        }
        if (!systemContentType.isEmpty()) {
            defaultUtil.setContentType(systemContentType);
        }
        if (!systemLocale.isEmpty()) {
            defaultUtil.setLocale(new Locale(systemLocale));
        }
        if (null == gzipswitch) {
            gzipswitch = new GzipSwitch();
        }
        if (null == markdownUtil) {
            markdownUtil = new MarkdownUtil(propertylist);
            markdownUtil.initOptions();
        } else {
            markdownUtil.initOptions();
        }
        if ((null != folderUtil.getIndex_folder()) && (!folderUtil.getIndex_folder().isEmpty())) {
            // Call a parallel thread to index the content in Lucene
            if (null == contentIndexer) {
                contentIndexer = new ContentIndexer(cfattributcontentService, indexService);
            }
            Thread contentindexer_thread = new Thread(contentIndexer);
            contentindexer_thread.start();
            LOGGER.info("CONTENTINDEXER RUN");
            if (null == assetIndexer) {
                assetIndexer = new AssetIndexer(cfassetService, indexService, propertylist);
            }
            Thread assetindexer_thread = new Thread(assetIndexer);
            assetindexer_thread.start();
            LOGGER.info("ASSETINDEXER RUN");
            indexService.getWriter().commit();
        }
        // Init Site Metadata Map
        if (null == metainfomap) {
            // hzMetainfomap = hcInstance.getMap("metainfos");
            metainfomap = new HashMap();
        }
        metainfomap.put("version", clownfishutil.getVersion());
        metainfomap.put("versionMojarra", clownfishutil.getVersionMojarra());
        metainfomap.put("versionTomcat", clownfishutil.getVersionTomcat());
        // Init Lucene Search Map
        if (null == searchcontentmap) {
            searchcontentmap = new HashMap<>();
        }
        if (null == searchassetmap) {
            searchassetmap = new HashMap<>();
        }
        if (null == searchassetmetadatamap) {
            searchassetmetadatamap = new HashMap<>();
        }
        if (null == searchclasscontentmap) {
            searchclasscontentmap = new HashMap<>();
        }
        if (null == searchmetadata) {
            searchmetadata = new HashMap<>();
        }
        searchlimit = propertyUtil.getPropertyInt("lucene_searchlimit", LuceneConstants.MAX_SEARCH);
        jobSupport = propertyUtil.getPropertyBoolean("job_support", jobSupport);
        if (jobSupport) {
            scheduler.clear();
            // Fetch the Quartz jobs
            quartzlist.init();
            quartzlist.setClownfish(this);
            List<CfQuartz> joblist = quartzlist.getQuartzlist();
            joblist.stream().forEach((quartz) -> {
                try {
                    if (quartz.isActive()) {
                        JobDetail job = newJob(quartz.getName());
                        scheduler.scheduleJob(job, trigger(job, quartz.getSchedule()));
                        System.out.println(ansi().fg(GREEN));
                        System.out.println("JOB SCHEDULE: " + quartz.getName());
                        System.out.println(ansi().reset());
                    }
                } catch (SchedulerException ex) {
                    LOGGER.error(ex.getMessage());
                }
            });
        }
        AnsiConsole.systemUninstall();
    } catch (SchedulerException | IOException ex) {
        LOGGER.error(ex.getMessage());
    }
    folderUtil.init();
    servicestatus.setMessage("Clownfish is online");
    servicestatus.setOnline(true);
    LOGGER.info("INIT CLOWNFISH END");
}
Also used : AuthTokenList(io.clownfish.clownfish.datamodels.AuthTokenList) ServletOutputStream(javax.servlet.ServletOutputStream) DatatableProperties(io.clownfish.clownfish.jdbc.DatatableProperties) DatatableNewProperties(io.clownfish.clownfish.jdbc.DatatableNewProperties) EmailProperties(io.clownfish.clownfish.mail.EmailProperties) DatatableUpdateProperties(io.clownfish.clownfish.jdbc.DatatableUpdateProperties) DatatableDeleteProperties(io.clownfish.clownfish.jdbc.DatatableDeleteProperties) CfClassLoader(io.clownfish.clownfish.compiler.CfClassLoader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) SAPConnection(de.destrukt.sapconnection.SAPConnection) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) DefaultPropertiesPersister(org.springframework.util.DefaultPropertiesPersister) RPY_TABLE_READ(io.clownfish.clownfish.sap.RPY_TABLE_READ) Model(org.apache.maven.model.Model) HibernateInit(io.clownfish.clownfish.datamodels.HibernateInit) CfClassCompiler(io.clownfish.clownfish.compiler.CfClassCompiler) GzipSwitch(io.clownfish.clownfish.interceptor.GzipSwitch) PostConstruct(javax.annotation.PostConstruct)

Aggregations

DefaultPropertiesPersister (org.springframework.util.DefaultPropertiesPersister)8 File (java.io.File)7 FileOutputStream (java.io.FileOutputStream)7 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)7 SAPConnection (de.destrukt.sapconnection.SAPConnection)1 CfClassCompiler (io.clownfish.clownfish.compiler.CfClassCompiler)1 CfClassLoader (io.clownfish.clownfish.compiler.CfClassLoader)1 AuthTokenList (io.clownfish.clownfish.datamodels.AuthTokenList)1 HibernateInit (io.clownfish.clownfish.datamodels.HibernateInit)1 GzipSwitch (io.clownfish.clownfish.interceptor.GzipSwitch)1 DatatableDeleteProperties (io.clownfish.clownfish.jdbc.DatatableDeleteProperties)1 DatatableNewProperties (io.clownfish.clownfish.jdbc.DatatableNewProperties)1 DatatableProperties (io.clownfish.clownfish.jdbc.DatatableProperties)1 DatatableUpdateProperties (io.clownfish.clownfish.jdbc.DatatableUpdateProperties)1 JDBCUtil (io.clownfish.clownfish.jdbc.JDBCUtil)1 ScriptRunner (io.clownfish.clownfish.jdbc.ScriptRunner)1 EmailProperties (io.clownfish.clownfish.mail.EmailProperties)1 RPY_TABLE_READ (io.clownfish.clownfish.sap.RPY_TABLE_READ)1 BufferedReader (java.io.BufferedReader)1