How can I attach a datarule to a data broker's key-generation operation? - aviarc

I have a Workflow SQL databroker in which the ID field is a sequential number with additional character padding, i.e. P001 or TM234.
I have defined the query for ID generation as:
<key-generation field="id" query="queries/asset-patent-get-id" />
which simply retrieves next sequence value based on provided parameters. So for every created record I need to make sure that by the time ID gets stored in database it was already padded as per required rules and stored as a string rather than just a number.

First thing to note: a data rule isn't bound to an operation, but instead to a field. So in this case, just think of the key-generation operation as retrieving the next number in a sequence, nothing more. Once the sequence value is retrieved, an appropriate bound data rule should be able to format the sequence value before it is persisted.
You should be able to define a data rule something like this:
<!-- datarules/format-asset-patent-id/definition.xml -->
<data-rule name="format-asset-patent-id"
factory-class="com.aviarc.framework.datarule.xml.DefaultXMLDataRuleProviderFactoryImpl"
datarule-class="com.aviarc.framework.datarule.workflow.WorkflowDataRule">
<parameters>
<parameter name="field" mandatory="y"/>
</parameters>
<event name="onBeforeDatasetPersisted" workflow="workflows/format-asset-patent-id" field="{#field}"/>
</data-rule>
Then in the format-asset-patent-id workflow you can take care of formatting the id. (Note: I haven't had the chance to test whether the onBeforeDatasetPersisted event fires before or after the key-generation operation is performed.)
Then you could bind it with a data binding, for example:
<!-- databindings/asset-patent.xml -->
<databinding databroker="asset-patent"
factory-class="com.aviarc.framework.databinding.basic.BasicDataBindingFactoryImpl">
<on-dataset-bound>
<data-rules>
<format-asset-patent-id field="id"/>
</data-rules>
</on-dataset-bound>
</databinding>

Related

RDLC - calling a Subreport a variable number of times from a Report

I have a report designed in RDLC that has a Dataset consisting of a set of integer UserID values. The report consists of a one-column table, with each row grouped by UserID. Inside each cell is a subreport generated from the UserID. The subreport is also designed in RDLC from two separate datasets, each of which is generated based on the UserID.
How do I design the subreport to generate the appropriate information for each Parent row's UserID?
I don't see how it can be done on the parent report side, as the method defined in SubreportProcessingEventHandler appears to be called just once, rather than once for each UserID's Subreport.
I assume it has to be done in the Subreport's ascx.cs file - but where would I put it? Is there a predetermined method name to use, or do I call the method from the parent somehow?
Is what I am describing even possible?
Apparently, the answer - at least, the one that works when I do it - is, the SubreportProcessingEventHandler is, in fact, called once for each UserID, so the UserID is passed to the handler as a parameter, and the subreport's data sets are built within the handler using that UserID.

Retrieve query for time range (FetchXML/QueryExpression)

(Sorry for bad English)
I have an application that uses MS-CRM 2011 Web Service for retrieving last changes on crm Entities. This application Sync last data changes with a Windows Mobile device.
Sync operation occurs periodic every 20 minutes. In each sync operation I want to retrieve changes occurred from previous update by checking entities 'modifiedon' field.
Problem is that, CRM queries don't use Time piece of DateTime object and all change from the start of passed DateTime parameter been returned.
I'd check both FetchXML and QueryExpression, there is no different.
Is there any way to create a query for run on Crm WebService that return modified record from specified Date and time?
Sample (My FetchXml) :
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='new_brand'>
<attribute name='new_brandname' />
<attribute name='new_pdanumber' />
<filter type='and'>
<condition attribute='modifiedon' operator='on-or-after' value='2012/11/12 23:59'/>
</filter>
</entity>
</fetch>
See In the code, I wants all modified entities from 2012/11/12 23:00, but crm returns all modified record from 2012/11/12 00:00.
I have the same problem now with and oldest Dynamics CRM 2011 organization.The on or after comparation don't compare the time, only the date. Try using grater or equal ('ge' in fetchxml).
Your code is looking for records changed on or after 23:59... Your documented results sound correct.
In any case, the time part is used but i suspect you are seeing the result of user time versus universal time. If the users time zone offset != 0 then midnight as selected by the user in the UI will be different to the value stored in the database which is the UST equivalent.
We've added a new field (called ModifiedOnTick) to the Entity, and record the time difference in milliseconds with a fixed date (2011-01-01) in this field.

dynamodb creating a string set

I have a lot of objects with unique IDs. Every object can have several labels associated to it, like this:
123: ['a', 'hello']
456: ['dsajdaskldjs']
789: (no labels associated yet)
I'm not planning to store all objects in DynamoDB, only these sets of labels. So it would make sense to add labels like that:
find a record with (id = needed_id)
if there is one, and it has a set named label_set, add a label to this set
if there is no record with such id, or the existing record doesn't have an attribute named label_set, create a record and an attribute, and initialize the attribute with a set consisting of the label
if I used sets of numbers, I could use just ADD operation of UPDATE command. This command does exactly what I described. However, this does not work with sets of strings:
If no item matches the specified primary key:
ADD— Creates an item with supplied primary key and number (or set of numbers) for the attribute value. Not valid for a string type.
so I have to use a PUT operation with Expected set to {"label_set":{"Exists":false}}, followed (in case it fails) by an ADD operation. These are two operations, and it kinda sucks (since you pay per operation, the costs of this will be 2 times more than they could be).
This limitations seems really weird to me. Why are something what works with numbers sets would not work with string sets? Maybe I'm doing something wrong.
Using many records like (123, 'a'), (123, 'hello') instead of one record per object with a set is not a solutions: I want to get all the values from the set at once, without any scans.
I use string sets from the Java SDK the way you describe all the time and it works for me. Perhaps it has changed? I basically follow the pattern in this doc:
http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_UpdateItem.html
ADD— Only use the add action for numbers or if the target attribute is
a set (including string sets). ADD does not work if the target
attribute is a single string value or a scalar binary value. The
specified value is added to a numeric value (incrementing or
decrementing the existing numeric value) or added as an additional
value in a string set. If a set of values is specified, the values are
added to the existing set. For example if the original set is [1,2]
and supplied value is [3], then after the add operation the set is
[1,2,3], not [4,5]. An error occurs if an Add action is specified for
a set attribute and the attribute type specified does not match the
existing set type.
If you use ADD for an attribute that does not exist, the attribute and
its values are added to the item.
When your set is empty, it means the attribute isn't present. You can still ADD to it. In fact, a pattern that I've found useful is to simply ADD without even checking for the item. If it doesn't exist, it will create a new item using the specified key and create the attribute set with the value(s) I am adding. If the item exists but the attribute doesn't, it creates the attribute set and adds the value(s). If they both exist, it just adds the value(s).
The only piece that caught me up at first was that the value I had to add was a SS (String set) even if it was only one string value. From DynamoDB's perspective, you are always merging sets, even if the existing set is an empty set (missing) or the new set only contains one value.
IMO, from the way you've described your intent, you would be better off not specifying an existing condition at all. You are having to do two steps because you are enforcing two different situations but you are trying to perform the same action in both. So might as well just blindly add the label and let DynamoDB handle the rest.
Maybe you could: (pseudo code)
try:
add_with_update_item(hash_key=42, "label")
except:
element = new Element(hash_key=42, labels=["label"])
element.save()
With this graceful recovery approach, you need 1 call in the general case, 2 otherwise.
You are unable to use sets to do what you want because Dynamo Db doesn't support empty sets. I would suggest just using a string with a custom schema and building the set from that yourself.
To avoid two operations, you can add a "ConditionExpression" to your item.
For example, add this field/value to your item:
"ConditionExpression": "attribute_not_exists(RecordID) and attribute_not_exists(label_set)"
Source documentation.
Edit: I found a really good guide about how to use the conditional statements

How do I find parameter values from EntityQuery<T> class?

I have a seam 2.2 app. Basically I have a form with about 30 input fields. Each field is backed by a property is SearchForm.java. When I click "Submit" I invoke DevicesList.java (implements EntityQuery) and jump to /DevicesList.xhtml. All the input fields and properties correspond to parameters listed DevicesList.page.xml.
In other words in DevicesList.page.xml we have
<param name="hostname" value="#{searchForm.devName}"/>
<param name="loopback" value="#{searchForm.devIp}"/>
<param name="platform" value="#{searchForm.platform}"/>
etc.
I am heavily customizing getEjbql() based on which searchForm properties are set. I have been stepping through the seam framework code and trying to find a datastructure to access that contains a list of parameters that have been set from the form. Where are these things?
If I have entered a string into the hostname field of the form, the hostname parameter must be set to the value of #{searchFrom.devName}. But how do I find out that the hostname parameter has been set?
The only alternative I can think of is to use reflection and loop through all the classes of SearchFrom and then perform introspection on the object to see which ones have been set and build my sql query from that.
There has to be a better way. Anyone know how this could be done?
This is done automagically by Seam, meaning that it won't add a restriction for a field of the form that has no value, so if the user only inputs data on the, for example, devName and devIp fields, then the query will be something like:
select d from Device d where devName = ? and devIp = ?
even if your DevicesQuery also adds 27 more restrictions for all the fields, they won't be added to the query because they are empty

what is the point of an "ID" tag in xml?

<?xml version="1.0" encoding="utf-8" ?>
<Countries>
<Country>
<ID>1</ID>
<Name>Nepal</Name>
</Country>
<Country>
<ID>2</ID>
<Name>India</Name>
<Country>
<ID>3</ID>
<Name>China</Name>
</Country>
<Country>
<ID>4</ID>
<Name>Bhutan</Name>
</Country>
<Country>
<ID>5</ID>
<Name>USA</Name>
</Country>
</Country>
</Countries>
with the use of DataSet() i am extracting just the name of the country and putting it into dropdownlist in asp.net. what is the point of having that ID tag? is it an xml requirement?
It is not an XML requirement. It is likely there as a standard unique identifier. That way, if the name of the country ever changes (which seems to happen pretty frequently), that gives you the freedom to change it in this file without screwing up dependent data, as other data should be storing the ID, not the country name.
Another reason to use the ID, is that your application may need to display the same country name in different languages. Your application can then present the appropriate translated name to the user, but in terms of the data it stores once the user selects a country, that should strictly be based on ID.
Much of the time, an ID is a unique identifier. Say you wanted to have the possiblity that two countries could have the same name, then you would need an ID that is unique to each country. In your case, the ID does seem unnecessary, but keeping it in the file would be good practice.
I don't know that XML requires it per se, but for a lot of manipulations it's best to have a key value that's unique to the record, and numbers are best for that. It sounds like for your purposes it's fine to discard that information, but wherever it was produced it covering its bases so to speak for other potential uses.
It's a unique identifier, but in the case where you have country codes the code itself is usually unique anyway so it serves little purpose overall. It could be used as an indexer in the case where it is inconvenient to identify the individual record by name.
The appearance of the node could be related to a number of possibilities, all stemming from the data schema.
'ID' is probably a column in a validCountry table, and the ID and Country columns are being selected.
You're putting this in a drop down for a reason. The user will select a country and presumably, some data will be inserted or updated. Should you store the country name or the ID in this new/updated row? You would probably want a foreign key, using the ID to reference the country. Otherwise you get into weird situations when a country changes its name, for instance.
In fact I would think you will want the ID for the value attribute of the entries in the drop down (at least that's how it's often done.)

Resources