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?
Related
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.
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 {
...
}
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" />
I have two tables and I am using phalcon's phql to join them.
In my controller i have:
$oBuilder = $this->modelsManager->createBuilder();
$oBuilder->columns(['Tabone.*', 'Tabtwo.*']);
$oBuilder->from(['Tabone']);
$oBuilder->join('Tabtwo', 'Tabone.id = Tabtwo.id');
$oBuilder->where('Tabone.id = 1');
$aRecords = $oBuilder->getQuery()->execute();
/** #var Phalcon\Mvc\Model\Resultset\Complex $aRecords */
//this doesnt work as expected
$aRecords[0]->tabone->setVal(2);
echo "2 != ".$aRecords[0]->tabone->getVal()."<br>";
echo get_class($aRecords[0]->tabone).'<br>';
//this works as expected
$aRecords->getFirst()->tabone->setVal(2);
echo "2 == ".$aRecords->getFirst()->tabone->getVal()."<br>";
So, with the Phalcon's Complex Traversable resultset I am able to set properties using :
$resultset->getFirst()->tabone->setVal(2);
echo $resultset->getFirst()->tabone->getVal();
But when i try :
echo get_class($aRecords[0]->tabone); // Says tabone
$resultset[0]->tabone->setVal(2);
echo $resultset[0]->tabone->getVal();
the value remains unchanged. even though $aRecords[0]->tabone is the class Tabone.
These are my models
class Tabone extends \Phalcon\Mvc\Model
{
public $id;
public $val;
public function columnMap() {
return array( 'id' => 'id', 'val' => 'val' );
}
public function setVal($val) { $this->val = $val; }
public function getVal() { return $this->val; }
}
class Tabtwo extends \Phalcon\Mvc\Model
{
public $id;
public function columnMap() {
return array( 'id' => 'id' );
}
}
these are the mysql tables and values
CREATE TABLE tabone (
id INT(11) NOT NULL AUTO_INCREMENT,
val INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (id)
);
CREATE TABLE tabtwo (
id INT(11) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO tabone (id, val) VALUES (1, 1);
INSERT INTO tabtwo (id) VALUES (1);
Why are the setters/getters no working when using [0] ?
Am i doing something i shouldn't ? ...
because it is how it works. you have methods for these things available like:
offsetGet() // Gets row in a specific position of the resultset
getFirst() // Get first row in the resultset
getLast() // Get last row in the resultset
all methods are here: http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Resultset_Complex.html
it's good practice to not use array's key, to keep it simple imagine this:
you are using setters & getters, instead simply setting var's value. But when you want to implement new validation for some input field, you have to go through all the code where you set value, not only just edit your setter. i believe it has some same logic going on here, but i am not developing core of the phalcon, i if you want to get more details you should go check their C code here: https://github.com/phalcon/cphalcon
With information found on:
http://forum.phalconphp.com/discussion/945/why-properties-of-models-are-lost-
(...) when a resultset is traversed, only just one record is kept in memory,
if you modify a record changes will lost, because the record is freed
once it is not used anymore. This scheme is very efficient if you are
traversing big resultsets (...)
and on
Scala: What is the difference between Traversable and Iterable traits in Scala collections?
(...) complying with the Traversable interface does not require
keeping state
So, the reason why [0] does not set properties is because traversable means just
that, it only traverses the object, any values set directly in the traversed object
will be lost, because the object state is not kept.
This makes perfect sense especially when you are talking about large result sets
as it will save tons of memory.
Ibatis multi column datamapping to type handler.
I have a money object I am using which needs value and currency.
How to map multiple columns to same callbacktype handler?
Java Money object
http://www.javapractices.com/topic/TopicAction.do?Id=13
public class MoneyTypeHandlerCallBack implements TypeHandlerCallback {
//The below works but problems it always defaults currency. I need to be able to get Currency as well to use
// new Money(value, currency ) constructor
#Override
public Object getResult(final ResultGetter getter) throws SQLException {
BigDecimal value = getter.getBigDecimal();
if (value == null) {
return null;
}
Money result = new Money(value); // I need to be able to do new Money (value, currency)
return result;
}
... implment other...
}
SomeView Bean definition:
public class SomeView implements Serializable{
private String companyName
private Money netamount;
// .....geters and setters etc
}
SQLMAP Configurations:
<sqlMap namespace="myspace">
<typeAlias alias="someView" type="com.my.view.someView" />
<resultMap id="some_detail_view" class="someView">
<result property="companyName" column="COMPANY" />
...
<result property="netamount" column="NET_AMT" />
<result property="netamountCurrency" column="NET_AMT_CURRENCY" />
</resultMap>
<select id="someView" parameterClass="java.util.Map"
resultClass="someView" resultMap="some_detail_view">
SELECT COMPANY, NET_AMT, NET_AMT_CURRENCY From......
</select>
</sqlMap>