Call forwarding - voip

Okay so the problem here is I've been trying to find a dialplan for call forwarding but so far I've found only one on the official site, I configured it according to my requirement but it doesn't work, the call forward number is set but, the call doesn't get forwarded. Could you take a look at the code and tell me what's wrong?
Made some addition in default.xml in the dialplan folder as follows:
<extension name="call_forwarding_activativation">
 <condition field="destination_number" expression="^\*72$">
    <action application="play_and_get_digits" data="3 12 1 14000 # tone_stream://%(10000,0,350,440) silence_stream://250 cfwd_num \d+"/>     
    <action application="hash" data="insert/${domain_name}-call_forward/${caller_id_number}/${cfwd_num}"/>
    <action application="playback" data="tone_stream://${bong-ring}"/>
    <action application="hangup"/>
 </condition>
</extension>
  
<extension name="call_forwarding_deactivation">
 <condition field="destination_number" expression="^\*73$">       
    <action application="hash" data="delete/${domain_name}-call_forward/${caller_id_number}/${destination_number}"/>
    <action application="playback" data="tone_stream://${bong-ring}"/>
    <action application="hangup"/>
 </condition>
</extension>
  
<extension name="call_forwarding_number" continue="true">
 <condition>
    <action application="set" data="call_forwarding_number=${hash(select/${domain_name}-call_forward/${destination_number})}"/>
 </condition>
</extension>
And then added this part of the code to features.xml
<extension name="call_forwarding_activativation">
 <condition field="destination_number" expression="^\*72$">
    <action application="play_and_get_digits" data="3 12 1 14000 # tone_stream://%(10000,0,350,440) silence_stream://250 cfwd_num \d+"/>     
    <action application="hash" data="insert/${domain_name}-call_forward/${caller_id_number}/${cfwd_num}"/>
    <action application="playback" data="tone_stream://${bong-ring}"/>
    <action application="hangup"/>
 </condition>
</extension>
  
<extension name="call_forwarding_deactivation">
 <condition field="destination_number" expression="^\*73$">       
    <action application="hash" data="delete/${domain_name}-call_forward/${caller_id_number}/${destination_number}"/>
    <action application="playback" data="tone_stream://${bong-ring}"/>
    <action application="hangup"/>
 </condition>
</extension>
  
<extension name="call_forwarding_number" continue="true">
 <condition>
    <action application="set" data="call_forwarding_number=${hash(select/${domain_name}-call_forward/${destination_number})}"/>
 </condition>
</extension>
<extension name="check_call_forwarding" condition="true">
<!-- change the following regular expression to match the numbers that will utilize call forwarding-->
 <condition field="destination_number" expression="^(\d+)$">
  <action application="execute_extension" data="is_forward XML features"/>
  <action application="bridge" data="sofia/internal/$1#{domain_name}"/>
 </condition>
</extension>
I tried the code above to implement call forwarding, the forwarding number gets assigned but the call doesn't forward

Related

Parsing XML for sub children using using python

I am trying to parse the below XML to get the following data. There are multiple rules following, I have shared only one rule below. Is it possible to parse the XML for these values?
name from section header, rule id value, applied-to name, source names, source values, destination name, destination value.
<?xml version="1.0" encoding="UTF-8"?>
<filteredfirewallConfiguration timestamp="1621338984151">
<contextId>globalroot</contextId>
<layer3Sections>
<section id="asdfsdf" name="production" generationNumber="132" timestamp="1621930404081" managedBy="universalroot-0" tcpStrict="false" stateless="false" useSid="false" type="LAYER3">
<rule id="1213213" disabled="false" logged="true" managedBy="universalroot-0">
<name>From Conversion Server</name>
<action>allow</action>
<appliedToList>
<appliedTo>
<name>re-int-dx</name>
<value>universalwire</value>
<type>VirtualWire</type>
<isValid>true</isValid>
</appliedTo>
<appliedTo>
<name>re-ext-ap</name>
<value>universalwire</value>
<type>VirtualWire</type>
<isValid>true</isValid>
</appliedTo>
</appliedToList>
<sectionId>sfsdfafee</sectionId>
<sources excluded="false">
<source>
<name>sdfsdf101</name>
<value>ipset-werfwefdc</value>
<type>IPSet</type>
<isValid>true</isValid>
</source>
<source>
<name>sdfsfdf102</name>
<value>ipset-4wsetgfreds</value>
<type>IPSet</type>
<isValid>true</isValid>
</source>
</sources>
<destinations excluded="false">
<destination>
<name>production-database-cluster</name>
<value>sg</value>
<type>SecurityGroup</type>
<isValid>true</isValid>
</destination>
<destination>
<name>newname</name>
<value></value>
<type>IPSet</type>
<isValid>true</isValid>
</destination>
</destinations>
<services>
<service>
<name>servicenwe</name>
<value>application-dgfsdfg</value>
<type>Application</type>
<isValid>true</isValid>
</service>
</services>
<direction>inout</direction>
<packetType>any</packetType>
</rule>
sofar, I have been able to get the section header only.
import requests
import xml.etree.ElementTree as ET
tree = ET.parse("out.xml")
root = tree.getroot()
for child in root.find('./layer3Sections'):
print(child.tag, child.attrib)

Powershell command -- To add a attribute if not exist in a particular node of a XML

<APPPOOL APPPOOL.NAME="Classic" RuntimeVersion="v2.0" state="Started">
<add name="Classic" autoStart="true" managedRuntimeVersion="v2.0">
<APPPOOL APPPOOL.NAME="GetServiceDet" RuntimeVersion="v2.0" state="Started">
<add name="GetServiceDet" autoStart="true">
my file has many line begining with word "add name".
I want to check if these lines have a string "managedRuntimeVersion".
if not exists, then i need to add managedRuntimeVersion="v2.0" to
that line.
Expected Result as below
<APPPOOL APPPOOL.NAME="Classic" RuntimeVersion="v2.0" state="Started">
<add name="Classic" autoStart="true" managedRuntimeVersion="v2.0">
<APPPOOL APPPOOL.NAME="GetServiceDet" RuntimeVersion="v2.0" state="Started">
<add name="GetServiceDet" autoStart="true" managedRuntimeVersion="v2.0">
I have tried with the below script.. but in the result.. it is given only the lines having "add name"
$sfile="C:\Users\subash.s\Desktop\backup\pool.xml"
(((gc "$sfile") | Select-String -Pattern "add name" |
select-string -notmatch "managedRuntimeVersion") -replace '>',' managedRuntimeVersion="v2.0">') |
Set-Content "$sfile"
with the above script. i got below result..
<add name="Classic" autoStart="true" managedRuntimeVersion="v2.0">
<add name="GetServiceDet" autoStart="true" managedRuntimeVersion="v2.0">
For Pete's sake, the configuration file is XML, not a text file! Edit it as an XML document, and you will save a lot of headaches.
There are a few ways to add attributes into such a document. As the XML in the question is a fragment - and of illegal syntax, the sample code uses a bit modified version of the same. Select all add nodes that don't have got managedRuntimeVersion attribute, create one and add attribute with values to the nodes. Like so,
# Dummy data for testing
[xml]$x = #'
<root>
<APPPOOL APPPOOL.NAME="GetServiceDet" RuntimeVersion="v2.0" state="Started">
<add name="GetServiceDet2" autoStart="true"/>
</APPPOOL>
<APPPOOL APPPOOL.NAME="Classic" RuntimeVersion="v2.0" state="Started">
<add name="Classic" autoStart="true" managedRuntimeVersion="v2.0" />
</APPPOOL>
<APPPOOL APPPOOL.NAME="GetServiceDet" RuntimeVersion="v2.0" state="Started">
<add name="GetServiceDet" autoStart="true"/>
</APPPOOL>
</root>
'#
# Select all add elements that don't have managedRuntimeVersion attribute
$nl=$x.SelectNodes('/root/APPPOOL/add[not(#managedRuntimeVersion)]')
# Add attributes to the elements
foreach($n in $nl) {
# Create new attribute and assign a value
$a = $x.CreateAttribute('managedRuntimeVersion')
$a.Value = 'v2.0'
[void]$n.Attributes.Append($a)
}
# Print modified version to console
$x.save([console]::out)
# Output
<?xml version="1.0" encoding="ibm850"?>
<root>
<APPPOOL APPPOOL.NAME="GetServiceDet" RuntimeVersion="v2.0" state="Started">
<add name="GetServiceDet2" autoStart="true" />
</APPPOOL>
<APPPOOL APPPOOL.NAME="Classic" RuntimeVersion="v2.0" state="Started">
<add name="Classic" autoStart="true" managedRuntimeVersion="v2.0" />
</APPPOOL>
<APPPOOL APPPOOL.NAME="GetServiceDet" RuntimeVersion="v2.0" state="Started">
<add name="GetServiceDet" autoStart="true" managedRuntimeVersion="v2.0" />
</APPPOOL>
</root>
Reading the actual file and saving changes to disk are left as an exercise to the reader.

XML parsing for nested tags using python

i would need a help on how to parse xml files with nested tags taking the user input as attribute value of a particular tag.
for eg:
if xml code has 12 mappings and we want to select the below mapping name "m_IF1_TD_SALESORDER_STG_PR4_VBPA_BUSINESS_PARTNER" as user input and thereby printing the particular mapping details.
<MAPPING NAME="m_IF1_TD_SALESORDER_STG_PR4_VBPA_BUSINESS_PARTNER" DESCRIPTION="Data Mapping for loading Sales Order Business Partners from the staging database for PR4." OBJECTVERSION="1" ISVALID="YES" VERSIONNUMBER="1">
<TRANSFORMATION NAME="sq_STG_PR4_VBPA" DESCRIPTION="" TYPE="Source Qualifier" OBJECTVERSION="1" REUSABLE="NO" VERSIONNUMBER="1">
<TRANSFORMFIELD NAME="MANDT" DESCRIPTION="" DATATYPE="string" PORTTYPE="INPUT/OUTPUT" PRECISION="3" SCALE="0" PICTURETEXT="" DEFAULTVALUE="" EXPRESSION="MANDT" EXPRESSIONTYPE="GENERAL"/>
<TRANSFORMFIELD NAME="VBELN" DESCRIPTION="" DATATYPE="string" PORTTYPE="INPUT/OUTPUT" PRECISION="10" SCALE="0" PICTURETEXT="" DEFAULTVALUE="" EXPRESSION="VBELN" EXPRESSIONTYPE="GENERAL"/>
<TRANSFORMFIELD NAME="POSNR" DESCRIPTION="" DATATYPE="decimal" PORTTYPE="INPUT/OUTPUT" PRECISION="6" SCALE="0" PICTURETEXT="" DEFAULTVALUE="" EXPRESSION="POSNR" EXPRESSIONTYPE="GENERAL"/>
<TRANSFORMFIELD NAME="PARVW" DESCRIPTION="" DATATYPE="string" PORTTYPE="INPUT/OUTPUT" PRECISION="2" SCALE="0" PICTURETEXT="" DEFAULTVALUE="" EXPRESSION="PARVW" EXPRESSIONTYPE="GENERAL"/>
I would suggest using the XML ElementTree module of python.
It is very simple to use. For example:
import xml.etree.ElementTree as ET
tree = ET.parse('/filename.xml')
root = tree.getroot()
for subchild in root.findall('subchildName'):
print(subchild.get('subchildAttribute')

Eclipse4 - Application Model and Core Expressions definitions

In Application.e4xmi I have two perspectives:
...
<children xsi:type="advanced:PerspectiveStack" xmi:id="_ySFusPeXEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.perspectivestack.main">
<children xsi:type="advanced:Perspective" xmi:id="_83bVsPeXEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.perspective.testmanager" label="Test manager">
...
<children xsi:type="advanced:Perspective" xmi:id="_bDA4oPeaEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.perspective.configurator" label="Configurator">
...
and a main menu with two items:
<mainMenu xmi:id="_xanVgPfWEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.menu.0">
<children xsi:type="menu:HandledMenuItem" xmi:id="_22vnAPfWEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.handledmenuitem.uno" label="uno" command="_LFFTsPhHEeK44MdhTvpdlg">
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_28cw8PfXEeKXHJPsnYiiYQ" coreExpressionId="com.myapplication.ui.perspectiveselected.testmanager"/>
</children>
<children xsi:type="menu:HandledMenuItem" xmi:id="_49obAPfWEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.handledmenuitem.due" label="due" command="_NXT1APhHEeK44MdhTvpdlg">
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_ZP4lgPhHEeK44MdhTvpdlg" coreExpressionId="com.myapplication.ui.perspectiveselected.configurator"/>
</children>
</mainMenu>
The menu item "com.myapplication.ui.handledmenuitem.uno" has to be shown when perspective "com.myapplication.ui.perspective.testmanager" is shown.
The menu item "com.myapplication.ui.handledmenuitem.due" has to be shown when perspective "com.myapplication.ui.perspective.configurator" is shown.
So that, I defined in plugin.xml:
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="com.myapplication.ui.perspectiveselected.testmanager">
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="com.myapplication.ui.perspective.testmanager">
</equals>
</with>
</definition>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="com.myapplication.ui.perspectiveselected.configurator">
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="com.myapplication.ui.perspective.configurator">
</equals>
</with>
</definition>
</extension>
IT DOESN'T WORK !! (menu items are shown always)
Any ideas?
I see that you have applied on the definition itself. Create a new command and register it with your menu and then write your expression on it.
Example:
<command
commandId=" "
label=" "
mnemonic="A">
<visibleWhen
checkEnabled="false">
<with
variable="">
<equals
value="1">
</equals>
</with>
</visibleWhen>
</command>

How can i create a hierarchical dimension for dates in ActivePivot?

I'm a newbe in ActivePivot and i want to create a dimension with DimensionType = time, where the dates a shown in hierachical manner. E.g. for 30.01.2013 i need one level for the year -> 2013 (sort descending), one level for the month (also sort descending) -> 1 and one level for the days (also sort descending) -> 30, 29, 28, ...
Viewed via ActivePivotLive should look like:
- 2013
- 1
- 30
- 29
- 28
- ...
+ 2012
+ 2011
and so on.
I went through the ActivePivot sandbox project, but i didn't find anything that helps me. The TimeBucket dimension which i've found in the EquityDerivativesCube makes something similar but the buckets are created in a different manner.
How can i solve this problem?
Ok, i handle it out.
It is not necessary to make the round trip and to implement a dimension. It is easy done by levels and the a calculator.
Here the code from the EquityDerivativesCube.xml
<!-- Standard time buckets, bucketing performed at insertion -->
<dimension name="TimeBucket">
<properties>
<entry key="DimensionType" value="time" />
<entry key="IsAllMembersEnabled" value="true" />
</properties>
<level name="Year">
<properties>
<entry key="LevelType" value="TIME_YEARS" />
</properties>
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Month">
<properties>
<entry key="LevelType" value="TIME_MONTHS" />
</properties>
<comparator pluginKey="Custom">
<order name="firstObjects">
<value>Jan</value>
<value>Feb</value>
<value>Mrz</value>
<value>Apr</value>
<value>Mai</value>
<value>Jun</value>
<value>Jul</value>
<value>Aug</value>
<value>Sep</value>
<value>Okt</value>
<value>Nov</value>
<value>Dez</value>
</order>
</comparator>
</level>
<!-- The Value Date level is the field Date -->
<level name="Value Date" property="Date">
<properties>
<entry key="LevelType" value="time" />
</properties>
<comparator pluginKey="ReverseOrder" />
</level>
</dimension>
I added the following snippet to PNLCalculator.enrichTrade:
...
pnl = pnlVega + pnlDelta;
// Year and month calculations BEGIN
final Calendar cal = CALENDAR.get();
cal.setTime(trade.getDate());
final int year = cal.get(Calendar.YEAR);
final String month = DateFormatSymbols.getInstance(GERMANY).getShortMonths()[cal.get(MONTH)];
// Year and month calculations END
// instantiate the result that will hold the enrichment data
final PNLCalculatorResult result = new PNLCalculatorResult();
...
// add them to the result
result.setYear(year);
result.setMonth(month);
...
I also extended the SanboxFields.xml with the two new fields:
...
<field name="Year" type="integer" />
<field name="Month" type="string" />
...
Cheers!
The TimeBucket dimension in the ActivePivot Sandbox application defines a custom bucketing based on financial time periods. Creating a standard year > month > day hierarchy is actually simpler and seamless in ActivePivot. In the description if the schema you need to declare three fields (one for year, one for month and one for the day).
<field name="Year" indexation="dictionary" />
<field name="Month" indexation="dictionary" />
<field name="Day" indexation="dictionary" />
And then you need to declare a dimension that references those fields.
<dimension name="Time">
<level name="Year" />
<level name="Month" />
<level name="Day" />
</dimension>
Then ActivePivot will build the time hierarchy incrementally, by introspecting the loaded records.
This will work automagically if the input records (objects) already contain a Year attribute, a Month attribute and a Day atribute (For instance if the input records are POJOs with getYear(), getMonth() and getDay() methods). If that is not the case and that for instance the input records only have a date attribute, you can either transform your records before puutting them into ActivePivot, or inject a calculator in ActivePivot (com.quartetfs.biz.pivot.classification.ICalculator) that will on the fly compute the three fields from the date. Look at the ActivePivot Sandbox application for an example of calculator.
Extracting those fields is usually done with standard Java code:
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
System.out.println("Date: " + date);
System.out.println("Year: " + calendar.get(Calendar.YEAR));
System.out.println("Month: " + calendar.get(Calendar.MONTH) + 1);
System.out.println("Day: " + calendar.get(Calendar.DAY_OF_MONTH));
About the ordering of members in the level of a dimension, ActivePivot per default uses the natural ordering of java objects (those that implement java.lang.Comparable interface) so dates and integers will be sorted from the lowest to the greatest. You can easily reverse that by declaring a "ReverseOrder" comparator on the target level(s).
<dimension name="Time">
<level name="Year">
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Month">
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Day">
<comparator pluginKey="ReverseOrder" />
</level>
</dimension>

Resources