/*
 * $Id$
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log$
 * Revision 1.15  2007/08/09 14:38:55  marbobo
 * - 2 falsch zugeordnete LDAP- Parameter entfernt
 * + Löschen und Aktivieren von Lizenzen hinzugefügt
 *
 * Revision 1.14  2007/02/12 13:13:33  marbobo
 * + Licensedatei für VKCDemo-System
 *
 * Revision 1.13  2006/09/07 01:54:02  marbobo
 * + TabIds überarbeitet
 *
 * Revision 1.12  2006/04/04 17:03:08  marbobo
 * + Neue Systemparameter hinzugefügt (Konvertierungsformate)
 *
 * Revision 1.11  2005/12/01 17:06:59  jonyp
 * enable classicView for kachel license
 *
 * Revision 1.10  2005/12/01 10:20:35  jonyp
 * added license for kachel.biz
 *
 * Revision 1.9  2005/10/18 15:56:49  marbobo
 * + Trash-Systemparameter entfernt damit die Werte aus der Datenbank übernommen werde
 *
 * Revision 1.8  2005/10/18 14:49:58  jonyp
 * set doc_tab to be hidden
 *
 * Revision 1.7  2005/10/18 14:48:43  jonyp
 * do everthing correctly
 *
 * Revision 1.6  2005/10/18 10:24:48  jonyp
 * + bug fix: setHide(false) for those features, which are VISIBILE for UNI_BI
 * + rename methods for creation of license.dat for uni bielefeld
 * + added arg parameter for creation of uni_bi license.dat
 *
 * Revision 1.5  2005/09/16 09:24:50  jonyp
 * added id/log tags
 *
 */
package vkc.license;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashMap;

import vkc.db.entities.VKCSysParameter;
import vkc.util.ObjectCloner;
import vkc.util.VKCCoder;
import vkc.view.TabUniqueName;
import vkc.view.bean.TabInfo;

public class LicenseManager {
	private LicenseManager() {
	}
	
	static HashMap getUniBiSystemParameters() {
		HashMap sysParams = new HashMap();
		VKCSysParameter p = SystemParameters.getSystemParameter("ARCHIVECATEGORY", "EnableArchiveCategory");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("ARCHIVECATEGORY", "ArchiveCategoryPath");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("DOCUMENT", "EnableDocumentStatusCoverage");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("DOCUMENT", "EnableDocumentClassCoverage");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("PROJECTMANAGEMENT", "EnableProjectManagement");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("PROJECTMANAGEMENT", "ProjectRootCategoryId");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("PROJECTMANAGEMENT", "TemplatesRootCategoryId");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("FUNCTIONALVIEW", "FunctionalViewRootCategoryId");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("LDAP", "EnableLdapSupport");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("CATEGORYVIEW", "EnableClusterCategory");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("DOCUMENT", "EnableMultiIcon");
		p.setValuestring("0");
        p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("WORKFLOW", "Enable");
		p.setValuestring("0");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("WORKFLOW", "SendMail");
		p.setValuestring("0");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("WORKFLOW", "ShowDatatype");
		p.setValuestring("0");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		p = SystemParameters.getSystemParameter("VKCSTREAMS", "EnablePDF");
		p.setValuestring("0");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

		return sysParams;
	}
    
	static HashMap getUniBiTabViews() {
		HashMap tabViews = new HashMap();
		
		TabInfo tab = TabViews.getTabView(TabUniqueName.DOCUMENT_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.WORKFLOW_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setEnabled(false);
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.TRASH_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.FAVORITES_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.HISTORY_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.LATESTADDITIONS_TAB);
		tab.setViewTypeId(new Integer(2));		
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.BESTSELLER_TAB);
		tab.setViewTypeId(new Integer(2));		
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.SEARCH_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.MESSENGER_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.PROFILE_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.NEWS_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.HELP_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_USERMANAGEMENT_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_GROUPMANAGEMENT_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_ACTIVEUSERS_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SENDEMAIL_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SYSTEMPARAMETERS_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SYSTEMDEFAULTS_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SYSTEMMAINTENANCE_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_NEWSMANAGEMENT_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SHOWSTATISTICS_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_LDAP_TAB);
		tab.setViewTypeId(new Integer(2));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		return tabViews;
	}
    
    static HashMap getKachelSystemParameters() {
        HashMap sysParams = new HashMap();
        VKCSysParameter p = SystemParameters.getSystemParameter("ARCHIVECATEGORY", "EnableArchiveCategory");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("ARCHIVECATEGORY", "ArchiveCategoryPath");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("LDAP", "EnableLdapSupport");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("CATEGORYVIEW", "EnableClusterCategory");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("DOCUMENT", "EnableMultiIcon");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("WORKFLOW", "Enable");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("WORKFLOW", "SendMail");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("WORKFLOW", "ShowDatatype");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("STATISTICS", "EnableStatistics");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);
        
        p = SystemParameters.getSystemParameter("PROJECTMANAGEMENT", "EnableProjectManagement");
        p.setValuestring("1");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);        
        
        p = SystemParameters.getSystemParameter("LOGIN", "UserLockEnabled");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("LOGIN", "UserLockNotification");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("LOGIN", "MaxPwdMismatchCount");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        p = SystemParameters.getSystemParameter("LOGIN", "UserLockTime");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);
        
		p = SystemParameters.getSystemParameter("VKCSTREAMS", "EnablePDF");
		p.setValuestring("0");
		p.setHide(new Integer(1));
		
		sysParams.put(p.getContext() + "_" + p.getName(), p);

        return sysParams;
    }
    
    static HashMap getKachelTabViews() {
        HashMap tabViews = new HashMap();
        
        TabInfo tab = TabViews.getTabView(TabUniqueName.DOCUMENT_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.WORKFLOW_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setEnabled(false);
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.TRASH_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.FAVORITES_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.HISTORY_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.LATESTADDITIONS_TAB);
        tab.setViewTypeId(new Integer(1));      
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.BESTSELLER_TAB);
        tab.setViewTypeId(new Integer(1));      
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.SEARCH_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.MESSENGER_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.PROFILE_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.NEWS_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

        tab = TabViews.getTabView(TabUniqueName.HELP_TAB);
        tab.setViewTypeId(new Integer(1));
        tab.setHide(true);      

        tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_USERMANAGEMENT_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_GROUPMANAGEMENT_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_ACTIVEUSERS_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SENDEMAIL_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SYSTEMPARAMETERS_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SYSTEMDEFAULTS_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SYSTEMMAINTENANCE_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_NEWSMANAGEMENT_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_SHOWSTATISTICS_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

		tab = TabViews.getTabView(TabUniqueName.ADMIN_LDAP_TAB);
		tab.setViewTypeId(new Integer(1));
		tab.setHide(true);		

		tabViews.put(tab.getUniqueName(), tab);

        return tabViews;
    }
    
    
	static HashMap getVKCDemoSystemParameters() {
        HashMap sysParams = new HashMap();
        VKCSysParameter p = SystemParameters.getSystemParameter("LOGIN", "EnableUserRegistration");
        p.setValuestring("0");
        p.setHide(new Integer(1));
        p.setReadOnly(true);
        
        sysParams.put(p.getContext() + "_" + p.getName(), p);

        return sysParams;
	}
	
	static HashMap getVKCDemoTabViews() {
		return new HashMap();
	}
	
	static HashMap getFullSystemParameters() {
		return new HashMap();
	}
	
	static HashMap getFullTabViews() {
		return new HashMap();
	}
	
	public static void main(String[] args) {
		HashMap sysParams = null;
		HashMap tabViews = null;
		String licenseFileName = "";
        
        // change path to your needs...
        String path = "c:/projects/VKC3/defaultroot/WEB-INF/";

        System.out.println("Try to write configuration for " + args[0] + " ...");
        
        if (args.length == 0) {
            sysParams = LicenseManager.getFullSystemParameters();
            tabViews = LicenseManager.getFullTabViews();
            // don't forget to rename into "license.dat" !!!
            licenseFileName = "license.dat.full";
        } else {           
            if ("uni_bi".equals(args[0])) {
                sysParams = LicenseManager.getUniBiSystemParameters();
                tabViews = LicenseManager.getUniBiTabViews();
                // don't forget to rename into "license.dat" !!!
                licenseFileName = "license.dat.uni_bi";
            } else if ("kachel".equals(args[0])) {
                    sysParams = LicenseManager.getKachelSystemParameters();
                    tabViews = LicenseManager.getKachelTabViews();
                    // don't forget to rename into "license.dat" !!!
                    licenseFileName = "license.dat.kachel";
            } else if ("vkcdemo".equals(args[0])) {
                sysParams = LicenseManager.getVKCDemoSystemParameters();
                tabViews = LicenseManager.getVKCDemoTabViews();
                // don't forget to rename into "license.dat" !!!
                licenseFileName = "license.dat.vkcdemo";
            } 
            
        }
        
        if (licenseFileName.length() != 0) {
            try {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(bos);
                oos.writeObject(ObjectCloner.toString(sysParams));
                oos.writeObject(ObjectCloner.toString(tabViews));
                oos.flush();
                oos.close();
                
                FileOutputStream fos = new FileOutputStream(path + licenseFileName);
                fos.write(VKCCoder.base64Encode(bos.toByteArray()));
                fos.flush();
                fos.close();
                
                System.out.println("... " + licenseFileName + " written!");
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("Unkown configuration! No license file written !");
        }
	}
}