###############################################################################
#
# Open iT Patch definition
#

# Stop service
stop
{
	error=warning
	module=server
}

# Wait for all previously signalled programs to stop
waitstop
{
	error=fatal
	timeout=60
	kill=no
}

install
{
	error=fatal
	source=bin/openit_filtrator.exe
	target=%installdir%/bin/openit_filtrator.exe
}

install
{
	error=fatal
	source=bin/openit_archiver.exe
	target=%installdir%/bin/openit_archiver.exe
}

install
{
	error=fatal
	source=conf/licenseevents-total-usage.xml
	target=%installdir%/Configuration/Components/filtrator/licenseevents-total-usage.xml
}

install
{
	error=fatal
	source=conf/licenseevents-individual-usage.xml
	target=%installdir%/Configuration/Components/filtrator/licenseevents-individual-usage.xml
}

install
{
	error=fatal
	source=conf/licenseevents-usergroups.xml
	target=%installdir%/Configuration/Components/filtrator/licenseevents-usergroups.xml
}

install
{
	error=fatal
	source=conf/licenseevents-denied.xml
	target=%installdir%/Configuration/Components/filtrator/licenseevents-denied.xml
}

# Back up configuration file before modifying it
backup
{
	error=fatal
	source=%confdir%/acc_types
}

backup
{
	error=fatal
	source=%confdir%/Components/datagroup-generation.xml
}

backup
{
	error=fatal
	source=%confdir%/ConfBuilder-server.conf
}

backup
{
	error=fatal
	source=%confdir%/data_generation_config
}

backup
{
	error=fatal
	source=%confdir%/modules
}
backup
{
	error=fatal
	source=%confdir%/Components/archiver.xml
}
backup
{
	error=fatal
	source=%confdir%/classvar_mapping_config
}
backup
{
	error=fatal
	source=%confdir%/Components/LogMessages/daft.mess
}

install
{
	error=warning
	source=conf/daft.mess
	target=%installdir%/Configuration/LogMessages/daft.mess
}

# Modify acc_types
linepatch
{
	error=fatal
	condition=openitversion == 6020007 | openitversion == 6020011
	target=%confdir%/acc_types
	instr1=find  (Individual^license^use^licenseevents,
	instr2=seek 11
	instr3=replace    Group^type,
	instr4=seek 1
	instr5=replace    Group,
	instr6=seek 1
	instr7=replace    User^name)),
	instr8=find (Usergroup^license^use^licenseevents,
	instr9=seek 12
	instr10=replace    Group^type,
	instr11=seek 1
	instr12=replace    Group)),
}

linepatch
{
	error=warning
	target=%confdir%/acc_types
	instr1=find  (Denied^license^logfile,
	instr2=seek 1
	instr3=find  (Denied^licenseevents^logfile,
	instr4=replace  (Denied^license^use^licenseevents,
}
elselinepatch
{
	error=warning
	target=%confdir%/acc_types
	instr1=end
}

linepatch
{
	error=warning
	target=%confdir%/acc_types
	instr1=find  (Denied^license^use^licenseevents,
}
elselinepatch
{
	error=fatal
	target=%confdir%/acc_types
	instr1=find  (Petrel^concurrent^module^usage,
	instr2=seek 7
	instr3=replace    Used^licenses)),
	instr4=insert
	instr5=insert  (Denied^license^use^licenseevents,
	instr6=insert   (
	instr7=insert    (Count,Record^Count,x,SUM)
	instr8=insert   ),
	instr9=insert   (Product,
	instr10=insert   Feature,
	instr11=insert   Feature^version,
	instr12=insert   User^name,
	instr13=insert   Host^name,
	instr14=insert   Status,
	instr15=insert   Prime^time)
	instr16=insert  )
	instr17=insert
}

# Modify ConfBuilder-server.conf
linepatch
{
	error=fatal
	condition=openitversion == 6020007 | openitversion == 6020011
	target=%confdir%/ConfBuilder-server.conf
	instr1=find "Components/filtrator/licenseevents-total-usage.conf"		{ "Components/filtrator/licenseevents-total-usage.xml" }
}
elselinepatch
{
	error=fatal
	target=%confdir%/ConfBuilder-server.conf
	instr1=end
	instr2=insert "Components/filtrator/licenseevents-total-usage.conf"		{ "Components/filtrator/licenseevents-total-usage.xml" }
	instr3=insert "Components/filtrator/licenseevents-individual-usage.conf"	{ "Components/filtrator/licenseevents-individual-usage.xml" }
	instr4=insert "Components/filtrator/licenseevents-usergroups.conf"		{ "Components/filtrator/licenseevents-usergroups.xml" }
	instr5=insert "Components/filtrator/licenseevents-denied.conf"			{ "Components/filtrator/licenseevents-denied.xml" }
	instr6=insert
}

# Modify data_generation_config
linepatch
{
	error=warning
	condition=openitversion == 6020011 | openitversion == 6020007
	target=%confdir%/data_generation_config
	instr1=find TYPE:licenseevents:License events data:dynamic
}
elselinepatch
{
	error=warning
	condition=openitversion == 6020011 | openitversion == 6020007
	target=%confdir%/data_generation_config
	instr1=end
	instr2=insert 
	instr3=insert TYPE:licenseevents:License events data:dynamic
	instr4=insert 89:Total license use licenseevents:licenseevents-total-usage,P1D:on
	instr5=insert 90:Individual license use licenseevents:licenseevents-individual-usage,P1D:on
	instr6=insert 91:Usergroup license use licenseevents:licenseevents-usergroups,P1D:on
	instr7=insert 107:Denied license use licenseevents:licenseevents-denied,P1D:on
}


# Modify classvar_mapping_config
linepatch
{
	error=fatal
	condition=openitversion == 6020011 | openitversion == 6020007
	target=%confdir%/classvar_mapping_config
	instr1=find   (Usergroup^license^use^licenseevents,
	instr2=seek 1
	instr3=replace     (Prime^time),
	instr4=seek 1
	instr5=replace     ((Product, Feature), (Feature, Feature^version), (Group^type, Group))),
}

linepatch
{
	error=fatal
	target=%confdir%/classvar_mapping_config
	instr1=find   (Denied^license^use^licenseevents,
}
elselinepatch
{
	error=fatal
	target=%confdir%/classvar_mapping_config
	instr1=find   (Petrel^concurrent^module^usage,
	instr2=seek 2
	instr3=insert ,
	instr4=insert   (Denied^license^use^licenseevents,
	instr5=insert     (Prime^time, User^name, Host^name, Status),
	instr6=insert     ((Product, Feature)))
}

# Modify modules
linepatch
{
	error=fatal
	target=%confdir%/modules
	instr1=seek 4
	instr2=replace  (Open^iT^License^Analyzer, (9, 10, 16, 17, 37, 38, 43, 44, 45, 46, 47, 49, 50, 51, 52, 60, 61, 71, 72, 75, 76, 77, 83, 84, 85, 86, 89, 90, 91, 94, 95, 102, 104, 107))
}

# Modify archiver.xml
confremove
{
	error=warning
	target=%confdir%/Components/archiver.xml
	path=DCML.archiver.archive.licenseevents
}

confinsert
{
	error=fatal
	target=%confdir%/Components/archiver.xml
	path=DCML.archiver.archive
	name=licenseevents
	description=Supported type: License events log file
	type=DirName
	value=licenseevents
}

confremove
{
	error=warning
	target=%confdir%/Components/archiver.xml
	path=DCML.archiver.filtrate.licenseevents
}

confinsert
{
	error=fatal
	target=%confdir%/Components/archiver.xml
	path=DCML.archiver.filtrate
	name=licenseevents
	description=If type=licenseevents, run the following filter processes:
	type=String
	value=licenseevents-total-usage $BEG $END P1D,licenseevents-usergroups $BEG $END P1D,licenseevents-individual-usage $BEG $END P1D,licenseevents-denied $BEG $END P1D
}

# Modify datagroup-generation.xml
confremove
{
	error=warning
	target=%confdir%/Components/datagroup-generation.xml
	path=DCML.datagroup-generation.datagroups.licenseevents
}
confinsert
{
	error=fatal
	target=%confdir%/Components/datagroup-generation.xml
	path=DCML.datagroup-generation.datagroups
	name=licenseevents
	description=Data types for licenseevents
	type=String
	value=PelotonEventsParser.license.pelotonevents,DSLSEventsParser.license.dslsevents,IPSEventsParser.license.ipsevents,HaspEventsParser.license.haspevents,CatiaEventsParser.license.catiaevents,ParasoftEventsParser.license.parasoftevents,EAEventsParser.license.eaevents
}

# Start service
start
{
	error=warning
	module=server
}