XmlHttpRequest post request doesn't work React Native Android App - reactjs

In my application, there is a form that users fill and post soap action. This is a must soap because it's a ministry of healt procedure. XmlHttpRequuest post works fine in iOS devices. But doesn't work on android. I did a lot of research but didn't find anything. I am leaving the codes below.Please help me! Thanks!
const soapAction = async (xml, username, password,) => {//here is the post request func
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(
'POST',
'https://*****************************',
);
xmlhttp.timeout = 10000;
var text=xml.toString('utf16');
var sr=
'<?xml version="1.0" encoding="UTF-8"?>'+
'<soap:Envelope' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' xmlns:xs="http://www.w3.org/2001/XMLSchema"' +
' xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"' +
' xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"' +
' xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'+
'<soap:Header>'+
'<wsse:Security>'+
'<wsse:UsernameToken wsu:Id="SecurityToken-04ce24bd-9c7c-4ca9-9764-92c53b0662c5">'+
`<wsse:Username>${username}</wsse:Username>`+
`<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">${password}</wsse:Password>`+
'</wsse:UsernameToken>'+
'</wsse:Security>'+
'</soap:Header>'+
'<soap:Body>'+
'<***************************************************">'+
'<input>'+
'<![CDATA[' +
'<?xml version="1.0" encoding="utf-16"?>' +
`${text}`+
']]>'+
'</input>'+
'</**************>'+
'</soap:Body>'+
'</soap:Envelope>';
xmlhttp.setRequestHeader(
'SOAPAction',
'https://*****************************************',
);
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-16');
xmlhttp.setRequestHeader("Access-Control-Allow-Origin", "8");
xmlhttp.onload = async function () {
console.log(xmlhttp.responseText);
//alert(xmlhttp.responseText);
if (xmlhttp.responseText.includes("S0000")) {
Alert.alert("Başarılı ", "başarıyla sonuçlandı. ", [
{text: 'Tamam', onPress: () => cancel()},
],
{cancelable: true}
)
} else {
Alert.alert("Hata", "Lütfen Daha Sonra Tekrar Deneyiniz", [
{text: 'Tamam', onPress: () => null},
],
{cancelable: true}
) //it always here because response always null
}
};
xmlhttp.send(sr);
//console.log(xmlhttp);
};
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
//android manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="*/*" />
</intent>
</queries>
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:usesCleartextTraffic="true"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Related

log4c segmentation fault when calling rollingfile_udata_set_logdir

This is my code:
const char *logdir = ".";
const char *rollingpolicy_name = "rpolicy";
rollingfile_udata_t *rfup = NULL;
log4c_appender_t* app = NULL;
app = log4c_appender_get("rfileappender");
log4c_rollingpolicy_t *rollingpolicyp = NULL;
rfup = rollingfile_make_udata();
rollingfile_udata_set_logdir(rfup, logdir);
and this is the log4c4c file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE log4c SYSTEM "">
<log4c version="1.2.4">
<config>
<bufsize>0</bufsize>
<debug level="2"/>
<nocleanup>0</nocleanup>
<reread>1</reread>
</config>
<category name="root" priority="notice"/>
<category name="log4c.collector" priority="debug" appender="rfileappender"/>
<category name="six13log.log" priority="error" appender="stdout" />
<rollingpolicy name="rpolicy" type="sizewin" maxsize="1024" maxnum="10" />
<appender name="rfileappender" type="rollingfile" logdir="/var/log/" prefix="myprefixd" layout="dated" rollingpolicy="rpolicy" />
<appender name="stdout" type="stream" layout="basic"/>
<appender name="stderr" type="stream" layout="dated"/>
<layout name="basic" type="basic"/>
<layout name="dated" type="dated"/>
</log4c>
I get segmentation fault when calling rollingfile_udata_set_logdir(rfup, logdir);
adding:
#include <log4c/category.h>
#include <log4c/appender.h>
#include <log4c/layout.h>
#include <log4c/appender_type_rollingfile.h>
#include <log4c/rollingpolicy.h>
#include <log4c/rollingpolicy_type_sizewin.h>
solved it.

How To Implement Full Search in Case Type using Salesforce?

I need to build out a solution to create a search field on the new Case Type Data object in all 3 of the Level fields and populate based on selection.
Similar to SF Global Search I would like to type 2-3 characters in the text search field and it would find the matching text in the Level1-3 fields and when selected the Level 1-3 field would populate.
This is the apex class
public class PickListHandler {
#AuraEnabled
public static List<String> getLevel1(){
List<String> tempLst1 = new List<String>();
for(AggregateResult ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c group by Level_1__c])
{
tempLst1.add(''+ar.get('Level_1__c'));
}
return tempLst1;
}
#AuraEnabled
public static List<String> getLevel2(string strName){
List<String> tempLst2 = new List<String>();
for(AggregateResult ar : [select Level_2__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName group by Level_2__c])
{
tempLst2.add(''+ar.get('Level_2__c'));
}
return tempLst2;
}
#AuraEnabled
public static List<String> getLevel3(string strName1,string strName2){
List<String> tempLst3 = new List<String>();
for(AggregateResult ar : [select Level_3__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName1 and Level_2__c=:strName2 group by Level_3__c])
{
tempLst3.add(''+ar.get('Level_3__c'));
}
return tempLst3;
}
#AuraEnabled
public static String savecasetype(string level1,string level2,string level3,string id){
string strMsg='successfull';
try{
ERT_Case_Type__c obj=new ERT_Case_Type__c();
Obj.Case__c = id;
System.debug('CASE = '+ Obj.Case__c);
Obj.Level_1__c=level1;
System.debug('Level1 = '+ Obj.Level_1__c);
Obj.Level_2__c=level2;
System.debug('Level2 = '+ Obj.Level_2__c);
Obj.Level_3__c=level3;
System.debug('Level3 = '+ Obj.Level_3__c);
Insert obj;
}
catch(Exception ex){
strMsg='error';
}
return strMsg;
}
}
This is the Picklist handler component
<aura:component controller="PickListHandler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<!-- Actions-->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<!-- variable-->
<aura:attribute name="lstLevel1" type="String[]" />
<aura:attribute name="lstLevel2" type="String[]" />
<aura:attribute name="lstL3" type="String[]" />
<span> Level 1</span>
<ui:inputSelect aura:id="ddLevel1" change="{!c.getLvl1}">
<ui:inputSelectOption label="-Select-" value="true"/>
<aura:iteration items="{!v.lstLevel1}" var="value">
<ui:inputSelectOption label="{!value}" text="{!value}" />
</aura:iteration>
</ui:inputSelect>
<span>Level 2</span>
<ui:inputSelect aura:id="ddLevel2" change="{!c.getSelectedValue}">
<ui:inputSelectOption label="-Select-" value="true"/>
<aura:iteration items="{!v.lstLevel2}" var="value">
<ui:inputSelectOption label="{!value}" text="{!value}" />
</aura:iteration>
</ui:inputSelect>
<span>Level 3</span>
<ui:inputSelect aura:id="ddLevel3" >
<ui:inputSelectOption label="-Select-" value="true"/>
<aura:iteration items="{!v.lstL3}" var="value">
<ui:inputSelectOption label="{!value}" text="{!value}" />
</aura:iteration>
</ui:inputSelect>
<lightning:button variant="brand" label="Save" onclick="{!c.onConfirm}" />
</aura:component>
Regards,
Carolyn
You're asking for a lot, we wouldn't have your custom object. And this is old code, ui:inputSelect is deprecated for 1 year now. I'll try to help a bit but the whole thing needs your work too. And examples we can reproduce easily.
I'm going to cheat and use Philippe Ozil's ready component for the lookup/autocomplete thing.
It means you'd have to save LookupSearchResult class, the whole aura component and 2 aura events in your org before reading below. That's some prep work but it's battle-tested :)
Apex class
public with sharing class Stack64129038 {
#AuraEnabled(cacheable=true)
public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){
if(String.isBlank(searchTerm) || searchTerm.length() < 2){
return null;
}
String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what
List<Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c
FROM Case_Type_Data__c
WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t
ORDER BY Level_1__c, Level_2__c, Level_3__c
LIMIT 20];
/* You could also experiment with SOSL?
records = [FIND :('*' + searchTerm + '*') IN ALL FIELDS
RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0];
*/
List<LookupSearchResult> results = new List<LookupSearchResult>();
for(Case_Type_Data__c ctd : records){
results.add(new LookupSearchResult(ctd.Id, 'Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name,
String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ')
));
}
return results;
}
}
Aura component (html part)
<aura:component implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="Stack64129038">
<aura:attribute access="private" type="List" name="selection" default="[]"/>
<aura:attribute access="private" type="List" name="errors" default="[]"/>
<lightning:card title="New Case Type">
<lightning:recordEditForm aura:id="myForm" objectApiName="ERT_Case_Type__c" onsubmit="{!c.onSubmit}" onsuccess="{!c.onSuccess}">
<lightning:messages />
<c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search Case Types Data"/>
<lightning:inputField aura:id="Level_1__c" fieldName="Level_1__c" />
<lightning:inputField aura:id="Level_2__c" fieldName="Level_2__c" />
<lightning:inputField aura:id="Level_3__c" fieldName="Level_3__c" />
<lightning:button class="slds-m-top_small" variant="brand" type="submit" name="save" label="Save" />
</lightning:recordEditForm>
</lightning:card>
</aura:component>
Aura component - JS controller part
({
lookupSearch : function(component, event, helper) {
// Get the lookup component that fired the search event
const lookupComponent = event.getSource();
const serverSearchAction = component.get('c.search');
lookupComponent.search(serverSearchAction);
},
useSelected: function(component, event, helper) {
const selection = component.get('v.selection');
const errors = component.get('v.errors');
if (selection.length) {
if(errors.length){ // Clear errors, if any
component.set('v.errors', []);
}
let levels = selection[0].subtitle.split('; ');
component.find('Level_1__c').set('v.value', levels[0]);
component.find('Level_2__c').set('v.value', levels[1]);
component.find('Level_3__c').set('v.value', levels[2]);
}
},
onSubmit: function(component, event, helper) {
debugger;
event.preventDefault(); // stop the form from submitting
var fields = event.getParam('fields');
fields.Case__c = component.get('v.recordId'); // link to "this" Case
component.find('myForm').submit(fields);
},
onSuccess: function(component, event, helper){
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "Case Type saved OK, refreshing",
"type": "success"
});
toastEvent.fire();
$A.get('e.force:refreshView').fire(); // reload page
}
})

Powershell: Copy Elements from one array to another

Hi in my first array there are my nodes from a xml.
$result=Select-xml -xml $uar -xpath "//test:UAVariable[contains(#NodeId,'ns=1;s=::')][starts-with(#DataType,'i=')]" -namespace $ns | select -ExpandProperty node
now i have to filter this further more like this. And then if both if´s are true delete the element from my array if its possible or copy this Element to a new one.
$result | foreach {
$AttExists = $_.Arraydimensions
$NodeExists = $_.References.Reference.ReferenceType
if ($AttExists){
if ($NodeExists -eq 'HasComponent'){
#if this is happening i want to delete this hole Element (Node) in my array is this possible?
}
else{
#if deleting is not possible i want to copy these Element (Node) into a new array is this possible?
}
}
}
Tried several things like:
$_=$nullor whith a counter like $newArray[$i] = $result[$j] $i++
But it dont delete anything or copy it. Can someone help me?
xml data :
<?xml version="1.0" encoding="utf-8"?>
<UANodeSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:ua="http://xxx/NodeSet.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pv="http://yyy/NodeSet.xsd" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd">
<UAObject NodeId="ns=1;s=::" BrowseName="1:::">
<DisplayName><Default></DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">ns=2;i=10001</Reference>
<Reference ReferenceType="Organizes" IsForward="false">ns=2;i=20001</Reference>
<Reference ReferenceType="Organizes">ns=1;s=::AsGlobalPV</Reference>
<Reference ReferenceType="Organizes">ns=1;s=::Program</Reference>
</References>
<Extensions>
<Extension>
<pv:ObjectExtension>
<ACL>
<ACE Role="1" Allow="0x017F"/>
<ACE Role="2" Allow="0x015F"/>
</ACL>
</pv:ObjectExtension>
</Extension>
</Extensions>
</UAObject>
<UAObject ParentNodeId="ns=1;s=::" NodeId="ns=1;s=::AsGlobalPV" BrowseName="1:Global PV">
<DisplayName>Global PV</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=61</Reference>
<Reference ReferenceType="Organizes" IsForward="false">ns=1;s=::</Reference>
<Reference ReferenceType="Organizes">ns=1;s=::AsGlobalPV:gFahrzeug</Reference>
<Reference ReferenceType="Organizes">ns=1;s=::AsGlobalPV:gLebewesen</Reference>
</References>
</UAObject>
<UAVariable DataType="ns=1;i=100000" ParentNodeId="ns=1;s=::AsGlobalPV" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug" BrowseName="1:gFahrzeug" AccessLevel="3" ValueRank="-1">
<DisplayName>gFahrzeug</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">ns=1;i=100005</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<Value>
<Binding Type="PV" Target="::gFahrzeug"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
<UAVariable DataType="ns=1;i=100010" ParentNodeId="ns=1;s=::AsGlobalPV:gFahrzeug" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug" BrowseName="1:Kraftfahrzeug" AccessLevel="3" ValueRank="-1">
<DisplayName>Kraftfahrzeug</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">ns=1;i=100015</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.PKW</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<Value>
<Binding Type="PV" Target="::gFahrzeug.Kraftfahrzeug"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
<UAVariable DataType="i=3" ParentNodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW" BrowseName="1:LKW" AccessLevel="3" ValueRank="1" ArrayDimensions="2">
<DisplayName>LKW</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW[0]</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW[1]</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<Value>
<Binding Type="PV" Target="::gFahrzeug.Kraftfahrzeug.LKW"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
<UAVariable DataType="i=3" ParentNodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW[0]" BrowseName="1:LKW[0]" AccessLevel="3">
<DisplayName>LKW[0]</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<ACL>
<ACE Role="1" Allow="0x017F"/>
<ACE Role="2" Allow="0x015F"/>
</ACL>
<Value>
<Binding Type="PV" Target="::gFahrzeug.Kraftfahrzeug.LKW[0]"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
<UAVariable DataType="i=3" ParentNodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW[1]" BrowseName="1:LKW[1]" AccessLevel="3">
<DisplayName>LKW[1]</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<ACL>
<ACE Role="1" Allow="0x017F"/>
<ACE Role="2" Allow="0x015F"/>
</ACL>
<Value>
<Binding Type="PV" Target="::gFahrzeug.Kraftfahrzeug.LKW[1]"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
</UANodeSet>
Code:
[xml]$uar = Get-Content -Path 'C:\Users\strobel.ma\OneDrive - GEA\Desktop\XML to String\OpcUaMap(3)_28_07.uar'
$ns = New-Object System.Xml.XmlNamespaceManager($uar.NameTable) #asdf
$ns=#{GEA="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd";
ua="http://br-automation.com/OpcUa/configuration/NodeSet.xsd";
xsi="http://www.w3.org/2001/XMLSchema-instance";
uax="http://opcfoundation.org/UA/2008/02/Types.xsd";
xsd="http://www.w3.org/2001/XMLSchema";
pv="http://br-automation.com/OpcUa/PLC/PV.xsd"}
$result=Select-xml -xml $uar -xpath "//GEA:UAVariable[contains(#NodeId,'ns=1;s=::')][starts-with(#DataType,'i=')]" -namespace $ns | select -ExpandProperty node
$result | foreach {$_.NodeId = $_.NodeId -replace 'ns=1;s=::AsGlobalPV:'}
$result | foreach {$_.NodeId = $_.NodeId -replace 'ns=1;s=::'}
$result | foreach {
$AttExists = $_.Arraydimensions
$NodeExists = $_.References.Reference.ReferenceType
if ($AttExists){
if ($NodeExists -eq 'HasComponent'){
#if this is happening i want to delete this hole Element (Node) in my array is this possible?
}
else{
#if deleting is not possible i want to copy these Element (Node) into a new array is this possible?
}
}
}
I would suggest you a naive approach and just create a new $result2 object where you store exactly what you need
I guess the default System.Array type should be good enough:
declare the new variable where to store items:
$result2 = #()
and store in it whatever you want by using in your foreach loop the following:
$result2 += $_

Nested Looping inside a groovy xml builder

i am trying to create an XML file using groovy script. There is a requirement to loop two things, so that the resulting XML includes all the objects as passed by the user.
Here is the code so far, with the first loop:
import groovy.xml.*
//map to loop
def workflows = [[ name: "A", file: "fileA" , objectName: "wf_A" , objectType: "workflow", sourceRepository: "DEV2"],
[ name: 'B' , file: 'fileB' , objectName: 'wf_B' , objectType: 'workflow', sourceRepository: 'DEV2']]
// def folderNameMap = [[ srcFolder: ["srcFolder1", "srcFolder2"], TgtFolder: ["TgtFolder1", "TgtFolder2"]],
// [srcFolder: ["srcFolder3"], TgtFolder: ["TgtFolder3"]]
// ]
def builder = new StreamingMarkupBuilder()
builder.encoding = 'UTF-8'
def xml = builder.bind {
mkp.xmlDeclaration()
'udm.DeploymentPackage'(version:'$BUILD_NUMBER', application: "informaticaApp"){
deployables {
workflows.each { item ->
'powercenter.PowercenterXml'(name:item.name, file:item.file){
scanPlaceholders{ mkp.yield(true) }
sourceRepository{ mkp.yield(item.sourceRepository) }
'folderNameMap' {
entry( key:"multifolder", "{{multifolderTST}}" ) // <- this is hard code and i want to remove this
}
'objectNames' {
value { mkp.yield(item.objectName) }
}
'objectTypes' {
value { mkp.yield(item.objectType) }
}
}
}
}
dependencyResolution{ mkp.yield('LATEST') }
undeployDependencies{ mkp.yield(false) }
}
}
println XmlUtil.serialize(xml)
The resultant XML is:
<?xml version="1.0" encoding="UTF-8"?><udm.DeploymentPackage version="$BUILD_NUMBER" application="informaticaApp">
<deployables>
<powercenter.PowercenterXml name="A" file="fileA">
<scanPlaceholders>true</scanPlaceholders>
<sourceRepository>DEV2</sourceRepository>
<folderNameMap>
<entry key="multifolder">{{multifolderTST}}</entry>
</folderNameMap>
<objectNames>
<value>wf_A</value>
</objectNames>
<objectTypes>
<value>workflow</value>
</objectTypes>
</powercenter.PowercenterXml>
<powercenter.PowercenterXml name="B" file="fileB">
<scanPlaceholders>true</scanPlaceholders>
<sourceRepository>DEV2</sourceRepository>
<folderNameMap>
<entry key="multifolder">{{multifolderTST}}</entry>
</folderNameMap>
<objectNames>
<value>wf_B</value>
</objectNames>
<objectTypes>
<value>workflow</value>
</objectTypes>
</powercenter.PowercenterXml>
</deployables>
<dependencyResolution>LATEST</dependencyResolution>
<undeployDependencies>false</undeployDependencies>
</udm.DeploymentPackage>
This achieves the looping for the map declared as 'workflows' . There is another entry in the XML that needs to be iterated. The section in the script is
'folderNameMap' {
entry( key:"multifolder", "{{multifolderTST}}" ) // <- this is hard code and i want to remove this
}
I need to have this section iterated and create new line entries in the resulting XML, if multiple values were supplied to the script. Like:
<folderNameMap>
<entry key="multifolder">{{multifolderTST}}</entry>
<entry key="multifolder2">{{multifolderTST2}}</entry>
<entry key="multifolder3">{{multifolderTST3}}</entry>
</folderNameMap>
How can i define this 2nd map, so that the resultant XML looks like this: (the foldermap is a map. so i will have cases where only one srcFolder and a tgtFolder was given OR there will be times when there will be multiple srcFolder anb TgtFolders were given.)
<?xml version="1.0" encoding="UTF-8"?><udm.DeploymentPackage version="$BUILD_NUMBER" application="informaticaApp">
<deployables>
<powercenter.PowercenterXml name="A" file="fileA">
<scanPlaceholders>true</scanPlaceholders>
<sourceRepository>DEV2</sourceRepository>
<folderNameMap>
<entry key="multifolder">{{multifolderTST}}</entry>
</folderNameMap>
<objectNames>
<value>wf_A</value>
</objectNames>
<objectTypes>
<value>workflow</value>
</objectTypes>
</powercenter.PowercenterXml>
<powercenter.PowercenterXml name="B" file="fileB">
<scanPlaceholders>true</scanPlaceholders>
<sourceRepository>DEV2</sourceRepository>
<folderNameMap>
<entry key="multifolder1">{{multifolderTST1}}</entry>
<entry key="multifolder2">{{multifolderTST2}}</entry>
<entry key="multifolder3">{{multifolderTST3}}</entry>
</folderNameMap>
<objectNames>
<value>wf_B</value>
</objectNames>
<objectTypes>
<value>workflow</value>
</objectTypes>
</powercenter.PowercenterXml>
</deployables>
<dependencyResolution>LATEST</dependencyResolution>
<undeployDependencies>false</undeployDependencies>
</udm.DeploymentPackage>
So, I'm taking a stab in the dark here (as I'm not 100% sure I know what your question is), but assuming your input list can be changed to:
def workflows = [
[ name: 'A',
file: 'fileA',
objectName: 'wf_A',
objectType: 'workflow',
sourceRepository: 'DEV2',
folderNames: [ multifolder: '{{multifolderTST}}',
multifolder2: '{{multifolderTST2}}' ]],
[ name: 'B',
file: 'fileB',
objectName: 'wf_B',
objectType: 'workflow',
sourceRepository: 'DEV2',
folderNames: [ multifolder3: '{{multifolderTST3}}',
multifolder4: '{{multifolderTST4}}' ]]
]
Then, you can just do:
def builder = new StreamingMarkupBuilder()
builder.encoding = 'UTF-8'
def xml = builder.bind {
mkp.xmlDeclaration()
'udm.DeploymentPackage'(version:'$BUILD_NUMBER', application: "informaticaApp"){
deployables {
workflows.each { item ->
'powercenter.PowercenterXml'(name:item.name, file:item.file) {
scanPlaceholders(true)
sourceRepository(item.sourceRepository)
folderNameMap {
item.folderNames.each { name, value ->
entry(key:name, value)
}
}
objectNames {
value(item.objectName)
}
objectTypes {
value(item.objectType)
}
}
}
}
dependencyResolution('LATEST')
undeployDependencies(false)
}
}

msbuild itemgroup items

I have msbuild file which is executing batch file.
Msbuild file:
<PropertyGroup>
<ItemAString>Green;Red;Blue</ItemAString>
<ItemBString>Uno;Due;Tre</ItemBString>
<ItemCString>Song;Movie;Picture</ItemCString>
</PropertyGroup>
<ItemGroup>
<ItemsA Include="$(ItemAString.Split(';'))" />
<ItemsB Include="$(ItemBString.Split(';'))" />
<ItemsC Include="$(ItemCString.Split(';'))" />
</ItemGroup>
<Target Name = "CallBatch">
<!-- THIS DOES NOT WORK -->
<Exec Command="mybatch.bat %(ItemsA.Identity) %(ItemsB.Identity) %(ItemsC.Identity)" />
</Target>
Batch file is very simple:
echo Params = [%1] - [%2] - [%3]
I want to get next output:
Params = Green - Uno - Song
Params = Red - Due - Movie
Params = Blue - Movie - Picture
How to achieve this?
I found solution:
<Project DefaultTarget="DoTheMagic" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup Condition=" '$(TFP)'=='' ">
<TFP>$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll</TFP>
<TFP Condition=" !Exists('$(TFP)')">$(MSBuildFrameworkToolsPath)\Microsoft.Build.Tasks.v4.0.dll</TFP>
<TFP Condition=" !Exists('$(TFP)')">$(windir)\Microsoft.NET\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll</TFP>
</PropertyGroup>
<UsingTask
TaskName="Bukake"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(TFP)" >
<ParameterGroup>
<ItemsA Required="True" ParameterType="System.String"/>
<ItemsB Required="True" ParameterType="System.String"/>
<ItemsC Required="True" ParameterType="System.String"/>
<Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="True"/>
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
string[] itemsA = ItemsA.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries);
string[] itemsB = ItemsB.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries);
string[] itemsC = ItemsC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
List<TaskItem> items = new List<TaskItem>();
for (int index = 0; index < itemsA.Length; index++)
{
TaskItem item = new TaskItem();
item.ItemSpec = "item";
item.SetMetadata("itemA", itemsA[index]);
item.SetMetadata("itemB", itemsB[index]);
item.SetMetadata("itemC", itemsC[index]);
items.Add(item);
}
Result = items.ToArray();
]]>
</Code>
</Task>
</UsingTask>
<PropertyGroup>
<ItemAString>Green;Red;Blue</ItemAString>
<ItemBString>Uno;Due;Tre</ItemBString>
<ItemCString>Song;Movie;Picture</ItemCString>
</PropertyGroup>
<Target Name = "CallBatch">
<Message Text="$(TFS)" />
<Bukake ItemsA="$(ItemAString)"
ItemsB="$(ItemBString)"
ItemsC="$(ItemCString)">
<Output TaskParameter="Result" ItemName="Dundonja" />
</Bukake>
<ItemGroup>
<PreparedItems Include="#(Dundonja)"/>
</ItemGroup>
<!-- <Message Text="Dundonja: %(Dundonja.Identity) %(Dundonja.itemA) %(Dundonja.itemB) %(Dundonja.itemC)"/> -->
<Exec Command="mybatch.bat Dundonja %(Dundonja.Identity) %(Dundonja.itemA) %(Dundonja.itemB) %(Dundonja.itemC)"/>
</Target>

Resources