WCF Desrialization of date with offset - wcf

I am facing an issue where wcf response contains datetime stamp as
1978-05-20T11:12:00+2:00
I want to retrieve the response as the same like 1978-05-20T11:12:00.
Please note, this offset (+02:00 in the above example) value might change for different response. So value might be
1978-05-20T11:12:00+2:00
1978-05-20T11:12:00+5:00
1978-05-20T11:12:00+6:00

Here is what I did to fix this...
update the wsdl file from
<xs:element name="start" type="xs:date"/>
to
<xs:element name="start" type="xs:string"/>
and generated the proxy.. now the returned value with using this proxy was like 1978-05-20T11:12:00+2:00 in start field. they I used string function to extract just the desired part.
Alternatively, proxy file can be updated from
[XmlAttribute( type = "Date", ElementName = "start" )]
public DateTime start {
..
}
to
[XmlAttribute( type = "string", ElementName = "start" )]
public string start {
...
}

Related

How to hundle update many or some value of SQL Statement from WSO2 DataService?

I have a SQL Statement like this :
UPDATE students
SET name = :name, school = :school, grade = :grade
WHERE id = :id AND school = :school
I would like to expose this SQL as an API update using the WSO2 Dataservice.
It worked for me but i have to set all the value in the JSON payload like this :
{
"_putupdateprofile": {
"name":"oussama",
"school": "AL-ZOUHOUR",
"grade": "A1",
"id": 123
}
}
where my objectif is to be able to update only one value like this :
{
"_putupdateprofile": {
"name":"oussama",
"id": 123
}
}
So does WSO2 DataService support this?
I tried this and it worked for me but i still have problem to put where parameters optional
<param name="school" paramType="SCALAR" sqlType="STRING" optional="true" />
<param name="grade" paramType="SCALAR" sqlType="INTEGER" optional="true" />
Seems your requirement is to make some parameters optional. To make parameters optional you can add a default value as shown below.
<param name="school" paramType="SCALAR" sqlType="STRING" defaultValue="#{NULL}" />
<param name="grade" paramType="SCALAR" sqlType="INTEGER" defaultValue="#{NULL}" />
Note: You may have to change the default value based on the DB type.
Having said the above, If you don't want to update your record with the default values you may have to update your query to omit the fields you don't want to update in your query.

fluent validation, use multiple parameters for validation

I have the following xml.
<AttributeSet>
<KeyName>accountType</KeyName>
<KeyValue><val>administrator</val><val>developer</val></KeyValue>
<!-- valid values are String, Binary and Email, Datetime -->
<AttributeType>String</AttributeType>
<Desc>Type of Account for the owning user</Desc>
<Mandatory>True</Mandatory>
<PrimaryKey>False</PrimaryKey>
<LocalUnique>False</LocalUnique>
<GlobalUnique>False</GlobalUnique>
<CaseSensitive>True</CaseSensitive>
<ValidSet Lookup="False">
<TableLookup>Lookup</TableLookup>
<ColumnLookup>AccountType</ColumnLookup>
</ValidSet>
<Size>
<Min>1</Min>
<Max>8</Max>
</Size>
<Resusable>False</Resusable>
</AttributeSet>
I pass it to fluentvalidation which requires that the KeyValue must be checked for rules
like
1) <Mandatory>True</Mandatory> if this is true the keyvalue must exist.
2) <Size>
<Min>1</Min>
<Max>8</Max>
</Size>
keyvalue size must be between these values.
my code:
public class RecordValidator : AbstractValidator<Entity.EigenData.Record>
{
public RecordValidator()
{
//first match
RuleFor(rec => rec.KeyName).NotNull();
}
}
I really donot know how to check the min max and mandatory values using fluent rules.
any body can point?

spyne generating invalid schema

I am trying to use spyne from master branch as the released versions are not compatible with python3 and I have models defined like these:
class currency(ComplexModel):
data = XmlData(Decimal)
class mntCurrency(currency):
code = XmlAttribute(String)
class CreditLmt(ComplexModel):
curr = mntCurrency
I have plugged these models into a simple HelloWorld Service which returns CreditLmt in response. But when I try to run my soap server, spyne complains with the following:
lxml.etree.XMLSchemaParseError: Element
'{http://www.w3.org/2001/XMLSchema}extension': The content is not
valid. Expected is (annotation?, ((group | all | choice | sequence)?,
((attribute | attributeGroup)*, anyAttribute?)))., line 16
Which is correct because spyne generates the following xsd:
<xs:complexType name="mntCurrency">
<xs:complexContent>
<xs:extension base="tns:currency">
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="code" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
<xs:sequence>
<xs:element name="test" type="xs:token" minOccurs="0" nillable="true"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
I am using XmlData because I want to have reponse such that it looks like this:
<tns:currency code="826">10.0</tns:currency>
So how do I define my models?
An example for generating this element:
<tns:currency code="826">10.0</tns:currency>
... is as follows:
from spyne import *
from spyne.util.xml import get_object_as_xml
from lxml import etree
class Currency(ComplexModel):
value = XmlData(Decimal)
code = XmlAttribute(Integer32(values=[826, 234, 555]))
class SomeObject(ComplexModel):
handle = Unicode
currency = Currency
obj = SomeObject(handle="aaaa", currency=Currency(value=D('123.45'), code=555))
elt = get_object_as_xml(obj)
print(etree.tostring(elt, pretty_print=True))
As for the error, it is coming directly from libxml. It is essentially saying that the Xml Schema standard doesn't allow lone XmlData entries in a ComplexModel subclass. If you think this is an error, you must complain to the Xml Schema working group.

Mapping JAXBelement in Mule Data mapper

I have a generated SOAP response from a wsdl for one Web Service. This is how one of the elements looks like in the wsld definition:
<xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
In the POJO, it looks like this :
#XmlElementRef(name = "Name", namespace = "http://schemas.datacontract.org/2004/07/Web.WebServices", type = JAXBElement.class, required = false)
protected JAXBElement<String> name;
When trying to set the value, in the Data Mapper, I see the following:
The problem is that I am not allowed to just drag and drop the "name" value.
How should I map the name value from the JSON on the left to the name value?
You will have to drag input.name to the value field of name name/value.
Script view should look something like:
output.value = input.name;

Sorting on date field with Sitecore 7 ContentSearch

I'm trying to add a field sort to a date field in a ContentSearch query. I'm able to filter on the index field properly so I'm assuming the field is getting populated with values properly, however, results are not being sorted properly. Any thoughts? Here's the code I'm using to do query:
public static IEnumerable<Episode> GetPastEpisodes(Show show, bool includeMostRecent = false, int count = 0)
{
IEnumerable<Episode> pastEpisodes;
using (var context = _index.CreateSearchContext())
{
// querying against lucene index
pastEpisodes = context.GetQueryable<Episode>().Where(GetPastAirDatePredicate(show));
if(!includeMostRecent)
{
pastEpisodes = pastEpisodes.Where(item => item.Id != GetMostRecentEpisode(show).Id);
}
pastEpisodes = pastEpisodes.OrderByDescending(ep => ep.Latest_Air_Date);
if (count > 0)
{
pastEpisodes = pastEpisodes.Take(count);
}
pastEpisodes = pastEpisodes.ToList();
// map the lucene documents to Sitecore items using the database
foreach (var episode in pastEpisodes)
{
_database.Map(episode);
}
}
return pastEpisodes;
}
private static Expression<Func<Episode,bool>> GetPastAirDatePredicate(Show show)
{
var templatePredicate = PredicateBuilder.Create<Episode>(item => item.TemplateId == IEpisodeConstants.TemplateId);
var showPathPredicate = PredicateBuilder.Create<Episode>(item => item.FullPath.StartsWith(show.FullPath));
var airDatePredicate = PredicateBuilder.Create<Episode>(item => item.Latest_Air_Date < DateTime.Now.Date.AddDays(1));
var fullPredicate = PredicateBuilder.Create<Episode>(templatePredicate).And(showPathPredicate).And(airDatePredicate);
return fullPredicate;
}
The field is stored and untokenized and using the LowerCaseKeywordAnalyzer.
<field fieldName="latest_air_date" storageType="YES" indexType="UN_TOKENIZED" vectorType="NO" boost="1f" type="System.DateTime" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider"/>
</field>
Episode class has IndexField attribute set:
[IndexField("latest_air_date")]
public virtual DateTime Latest_Air_Date {get; set; }
Kyle,
As far as I can tell everything looks correct with your configuration and code. I mocked out something very similar in a vanilla Sitecore 7.2 instance and Dates sorted without issue.
One thing to note though, and this might be what is giving you some issues, is that Sitecore's FieldReader for DateTime only store the date portion of the DateTime. If you are expecting to be able to sort by true DateTime you will need to add a custom FieldReader or some computed fields.
See this blog that discusses the issue and explains the process to swap out a custom field reader: http://reasoncodeexample.com/2014/01/30/indexing-datetime-fields-sitecore-7-content-search/
I would also suggest looking at the index with Luke to verify what data is actually in the index. https://code.google.com/p/luke/
And finally you may want to enable Search debugging in Sitecore to see exactly how Sitecore is executing the query in Lucene.
Sitecore.ContentSearch.config:
<setting name="ContentSearch.EnableSearchDebug" value="true" />