SOAP + Zeep + XSD extension - python-3.x

Am interacting with a SOAP service through Zeep and so far it's been going fine, except I hit a snag with regards to dealing with passing values in anything related to an XSD extension.
I've tried multiple ways and am at my wits end.
campaignClient = Client("https://platform.mediamind.com/Eyeblaster.MediaMind.API/V2/CampaignService.svc?wsdl")
listPaging = {"PageIndex":0,"PageSize":5}
fact=campaignClient.type_factory("ns1")
parentType = fact.CampaignIDFilter
subtype=dict(parentType.elements)["CampaignID"] = (123456,)
combined= parentType(CampaignID=subtype)
rawData = campaignClient.service.GetCampaigns(Paging=listPaging,CampaignsFilter=combined, ShowCampaignExtendedInfo=False,_soapheaders=token)
print(rawData)
The context is the following :
this service is to get a list of items and it's possible to apply a filter to it, which is a generic type. You can then implement any type of filter matching that type, here a CampaignIDFilter.
My other attempts failed and the service used to pinpoint incorrect type or such but this way - which I think is on paper sound, gets me a 'something went wrong'.
I'm literraly implementing the solution found here : Creating XML sequences with zeep / python
Here's the service Doc http://platform.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v=3
Cheers

Turns out the right way to get there was to hack around a bit to get the right structure and use of types. The code itself :
objectType = campaignClient.get_type('ns1:CampaignIDFilter')
objectWrap = xsd.Element('CampaignServiceFilter',objectType)
objectValue = objectWrap(CampaignID=123456)
wrapperT = campaignClient.get_type('ns1:ArrayOfCampaignServiceFilter')
wrapper = xsd.Element("CampaignsFilter",wrapperT)
outercontent = wrapper(objectValue)
This ends up generating the following XML :
<soap-env:Body>
<ns0:GetCampaignsRequest xmlns:ns0="http://api.eyeblaster.com/message">
<ns0:CampaignsFilter>
<ns1:CampaignServiceFilter xmlns:ns1="http://api.eyeblaster.com/V1/DataContracts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:type="ns1:CampaignIDFilter">
<ns1:CampaignID>123456</ns1:CampaignID>
</ns1:CampaignServiceFilter>
</ns0:CampaignsFilter>
<ns0:Paging>
<ns0:PageIndex>0</ns0:PageIndex>
<ns0:PageSize>5</ns0:PageSize>
</ns0:Paging>
<ns0:ShowCampaignExtendedInfo>false</ns0:ShowCampaignExtendedInfo>
</ns0:GetCampaignsRequest>
</soap-env:Body>
Much credit to the user here which gave me the boiler plate needed to get this lovecraftian horror to work how to specify xsi:type zeep python

Related

Error setDate must implement interface DateTimeInterface symfony fixtures

I search in stackoverflow but i didn't find the answer.
I have this error :
Argument 1 passed to App\Entity\Matchs::setDate() must implement interface DateTimeInterface, bool given,
I have this in my fixtures :
$match1 = new Matchs();
$m1->setDescription('Description ')
->setDate(\DateTime::createFromFormat('d-m-Y hh:mm', '25-12-2001 20:30'))
$manager->persist($m1);
So I don't understand why it does not work because I have implemented the DateTimeInterface interface...
Thansk for help
The DateTime::createFromFormat failed do create a DateTime, and in this case return false.
I belive that problem is the format, instead 'd-m-Y hh:mm' try 'd-m-Y H:i'
You can see a complete list of you can use in the format here https://www.php.net/manual/en/datetime.format.php.

How can I call this jOOQ generated function taking a custom bound type?

I originally had the following SQL function:
CREATE FUNCTION resolve_device(query JSONB) RETURNS JSONB...
and the following code calling the method generated by jOOQ:
final JsonArray jsonArray = jooqDWH.select(resolveDevice(queryJson)).fetchOne().value1().getAsJsonArray();
final JsonObject o = jsonArray.get(0).getAsJsonObject();
This worked fine. I needed to return a real device object rather than a JSON blob though, so I changed the SQL function to:
CREATE FUNCTION resolve_device(query JSONB) RETURNS SETOF device...
and the code to:
final ResolveDeviceRecord deviceRecord = jooqDWH.fetchOne(resolveDevice(queryJson));
but I am getting a runtime error:
org.jooq.exception.SQLDialectNotSupportedException: Type class com.google.gson.JsonElement is not supported in dialect DEFAULT
Many other parts of my code continue to work fine with the custom binding I have converting JsonElement to JSONB, but something about the change to this function's signature caused it to stop working.
I tried a few different variants of DSL.field() and DSL.val() to try to force it to be recognized but have not had any luck so far.
This could be a bug in jOOQ or a misconfiguration in your code generator. I'll update my answer once it is clear what went wrong.
Workaround:
Meanwhile, here's a workaround using plain SQL:
// Manually create a data type from your custom JSONB binding first:
final DataType<JsonObject> jsonb = SQLDataType.OTHER.asConvertedDataType(jsonBinding);
// Then, create an explicit bind variable using that data type:
final ResolveDeviceRecord deviceRecord =
jooqDWH.fetchOptional(table("resolve_device({0})", val(queryJson, jsonb)))
.map(r -> r.into(ResolveDeviceRecord.class))
.orElse(null);

Create a collection of item ids Revit API in Python

So I am trying to use a list of input strings to isolate them in a view using Revit API. I got this far, but I am getting stuck where I am trying to create a set that takes all elements in a view and removes ones that are created from input IDs. I am doing this to end up with a set of all elements except ones that i want to isolate.
dataEnteringNode = IN0
view = IN0
str_ids = IN1
doc = __doc__
collector = FilteredElementCollector(doc, view.Id)
for i in str_ids:
int_id = int(i)
id = ElementId(int_id)
element = doc.GetElement(id)
element_set = ElementSet()
element_set.Insert(element)
elements_to_hide = collector.WhereElementIsNotElementType().Excluding(element_set).ToElements()
#Assign your output to the OUT variable
OUT = elements_to_hide
I would greatly appreciate a help in solving this error. I am getting that "expected ICollection[ElementId], got set". I am guessing the problem lies in a Excluding filter where i need to create a collection of Ids to exclude but I dont know how. Thank you in advance. Thank you for help in advance!
The reason your code doesn't work is that ElementSet in the Revit API does not implement the ICollection<T> interface - just the IEnumerable<T>. So, to get your code working, you will need to create an ICollection<T> object from your set.
Try something like this:
# ...
from System.Collections.Generic import List
element_collection = List[ElementId](element_set)
elements_to_hide = collector.WhereElementIsNotElementType().Excluding(element_collection).ToElements()

Reading Signature lines using OpenXMlSDK

I just started office development and have been trying to read a word 2013 document that holds signature fields in it using open xml sdk
can some one help me how to do that.
using (var document = WordprocessingDocument.Open(#"D:\Temp_Folder\tempfile.docx", false))
{
var docPart = document.MainDocumentPart;
}
I have tried reading word file using ELdos (SBOffice) I can get signature lines but not able to get full details related to Signature Lines like Suggested Signer and Suggested Signer email.
Can some one suggest me which I have to prefer OpenXMLSDK or Eldos(SBOffice) bcz i need to find signature fields and then sign them by custom certificate using Third party Signing Service.
The best way would be to use the OpenXMLSDKTool to open the document and it will show you the code necessary to replicate it. I believe it would be within a shape something like
using (var document = WordprocessingDocument.Open("YourDoc.docx", false)
{
var signature = document.MainDocumentPart.Document.Descendant<DocumentFormat.OpenXML.VML.Office.SignatureLine>().FirstOrDefault();
var suggestedSigner = signature.SuggestedSigner;
var suggestedSignerTitle = signature.SuggestedSigner2;
var suggestedSignerEmail = signature.SuggestedSIgnerEmail;
}
You could get the actual signature image in this same area.

Retrieving Properties from DbSqlQuery

Background: Project is a Data Import utility for importing data from tsv files into a EF5 DB through DbContext.
Problem: I need to do a lookup for ForeignKeys while doing the import. I have a way to do that but the retrieval if the ID is not functioning.
So I have a TSV file example will be
Code Name MyFKTableId
codevalue namevalue select * from MyFKTable where Code = 'SE'
So when I process the file and Find a '...Id' column I know I need to do a lookup to find the FK The '...' is always the entity type so this is super simple. The problem I have is that I don't have access to the properties of the results of foundEntity
string childEntity = column.Substring(0, column.Length - 2);
DbEntityEntry recordType = myContext.Entry(childEntity.GetEntityOfReflectedType());
DbSqlQuery foundEntity = myContext.Set(recordType.Entity.GetType()).SqlQuery(dr[column])
Any suggestion would be appreciated. I need to keep this generic so we can't use known type casting. The Id Property accessible from IBaseEntity so I can cast that, but all other entity types must be not be fixed
Note: The SQL in the MyFKTableId value is not a requirement. If there is a better option allowing to get away from SqlQuery() I would be open to suggestions.
SOLVED:
Ok What I did was create a Class called IdClass that only has a Guid Property for Id. Modified my sql to only return the Id. Then implemented the SqlQuery(sql) call on the Database rather than the Set([Type]).SqlQuery(sql) like so.
IdClass x = ImportFactory.AuthoringContext.Database.SqlQuery<IdClass>(sql).FirstOrDefault();
SOLVED:
Ok What I did was create a Class called IdClass that only has a Guid Property for Id. Modified my sql to only return the Id. Then implemented the SqlQuery(sql) call on the Database rather than the Set([Type]).SqlQuery(sql) like so.
IdClass x = ImportFactory.AuthoringContext.Database.SqlQuery<IdClass>(sql).FirstOrDefault();

Resources