ASP.NET: Best way to determine type of object serialized to XML - asp.net

I have a table in my SQL Server DB that holds auditing information for certain actions a user takes within my system. Things like who performed the action, when it was performed, and what action are all pieces of information that can easily span multiple actions. But depending on the action performed, there may be other information that I want to capture, that is specific to the action. To handle this, I elected to add an "XML Metadata" column to the table that holds serialized XML of different metadata objects that I've created. I created a metadata object for each of the actions that I'm interested in tracking extra for. So each object is responsible for tracking specific extra information (metadata) for it's action. The objects are serialized and written to my new column.
I have SystemAction objects that I use to store information from this table, and I've added a string field that holds the XML string from the DB. The problem is, when I'm reading this XML back from the SystemAction objects, I'm struggling with a way to generically translate it back into it's correct metadata object. Each metadata object is going to have different fields, and each object has it's own static method that takes an XML string and attempts to return the metadata object type. So I could say:
SomeActionMetadata mdObj = SomeActionMetadata.BuildFromXML(xmlStringFromDB);
But I really don't know of a way to say "Here's some XML that could translate to any number of different objects. Figure it out and give me the right object back."
Given my current implementation, I could always just assign a unique ID to each metadata object that is stored as a field in each object, then use a case statement to switch on that ID and use the appropriate class's static build method to build the right object. But I was hoping for something a little more automatic than that. What if I have a List of SystemAction objects and just want to loop through them and generate the correct metadata object type?
I was hoping someone might have run across something similar to this before, or could point me to an article or post that could help me out. Thanks very much.

As indicated by Subhash Dike in the comments below, there is a similar SO question here that was able to point me in the right direction.

Related

Get request data (GET) in a Symfony (5) formType without using data_class

I'm building a formType to filter products on a collection page. You can set multiple select boxes which makes other auto filled or unnecessary. I want to be able to manipulate the formType based on the data like when using a data_class object. I'm not using data_class because the search isn't a persisted object which is saved to the database. I'm using a GET form.
For example 2 select boxes:
category
productType
When setting a category makes some of the productTypes unnecessary. So i want to not show it.
To do so in the formType I need the data of the request (GET) but I can't find a way to do so.
To retrieve data from the form, you can use $form->getData().
As you're in a GET context, I suspect you can take advantage from FormEvents (take a closer look to POST_SET_DATA event) and get rid of values you don't need.
One other thing I would like to point out, is that you still can use some kind of object that's not persisted to DB, like DTO or whatever.
Forms and entities are not related anyhow, neither in the usage nor in the intentions.

Symfony axios pass only id or entire object?

I have a Booking entity which has a ManyToOne relationship with my Car entity. I use axios to post my data for creating a Booking. I'm not sure if it's better practice to pass my whole Car object to my create function inside my Controller or to only pass the Car's id to the route of the function (which then fetches the Car from my database thanks to Symfonys param converter). Or is there another way which is considered "best practice"?
It depends on your scenario and the way you want to use.
Whenever you have to create an object / row inside the database then you will have to pass the whole object. assuming that the cars has already been created inside the database and you only have to link the booking object with the car than i will prefer you to bind it using ids rather than placing the whole object.
If you place the whole car object than it will increase the retrieval performance but if someday the information of car is changed than you will have to change the information on every booking object in which you placed the car object but if you just bind it with the Car Id than it will always give user the latest information even if the info of Car has been changed.
I thought that it will reduce the performance of the application if we used Id but that is not the case the DBMS use indexing to manage the search and search through id takes not time. It performance is not an issue and yes if you pass a whole object than it will also consume more data (since a large amount of data will be uploaded).

Marketo REST API - is there a way to get all records of a custom object?

I created a custom object and i want to get all its existing records. Is there a way of doing that via the REST API? Seems like a very basic and simple operation but i couldn't find information about it anywhere.
As you say, it seems like a basic task, but in the reality, it is more complex indeed.
Unfortunately, the Get Custom Object endpoint (which is the only endpoint to fetch Custom Objects) requires the filterType and filterValues parameters to be present as well. Basically this means that you have to have some information about the queried objects beforehand.
Also, a further restriction is that the value of filterType can only be one of the “searchable” fields of the Custom Object, meaning that it has to be either a Link field or a Dedupe field. (These fields are listed under the searchableFields property in the response from the Describe Custom Objects endpoint.)
So as mentioned above, you have to know the values for at least one of the properties of your Custom Objects before you make the query.
With additional queries though, you can grab these required values.
Let's say, you have your Custom Object linked to the Lead Object, and the Link field is called Owner Email (with the REST API name being ownerEmail) which links to the Email Address field of the Lead Object. In this case you could set the filterType to ownerEmail and set the emails of the leads as filterValues.
Then it is up to you how you gather the emails of those Leads who has a Custom Object attached. Luckily the REST API won’t throw an error if you provide a value that has no corresponding Custom Objects.
If your Custom Object is linked to a Lead, it's a bit complex but you can do like this:
Create a smart list and filter with "Has You Custom Object"
Get the smart list with API (GET /rest/asset/v1/smartLists.json)
Based on this list of Leads, get all Custom Objects (see the other answer).

Displaying data in a datagrid in an Alfresco task form

I have a json array variable defined in my activity workflow definition. Now, I need to present the data of the json array in a datagrid inside a form task. One of those columns should be a check entry filed so that the user may select some rows. After that, I need to get back that data in a subsequent form task (so I need the data to be updated in the json variable so I can read it back, mainly the user selected checks).
Any example to accomplish this? I didnt find almos nothing relating with using datagrids in Alfresco task forms.
thank you!
Miguel

MyBatis 3.x trying to read a collection and populate the objects

I'm new to MyBatis and my project requires me to read the data from the Oracle database, populate the objects, reset the data if necessary and insert it back into the database.
I'm trying to read data of a nested table. The nested table column consists of a collection of Oracle defined Custom Objects. To be more specific each record in the table is associated to a collection of Custom Object and the Custom Object consists of three fields namely nickname, date of birth and address.
I'm actually getting an oracle.sql.ARRAY data type when trying to retrieve the data. The problem I have here is that I'm not able to map this oracle.sql.ARRAY which is being fetched by the JDBC through MyBatis to my objects. All I'm able to do is get the ARRAY cast it to an object array and then to a Struct and iterate through the attributes to get the values.
I can always hand build the beans, but I know its not an efficient way of doing it. I want to configure my result map in a way that it populates my objects. But, I have not been able to do that so far. If anyone has any advice regarding this issue please help me out.
I think you can get this to work with a custom TypeHandler.
In your ResultMap, do something like this:
<result property="arrayOne" column="array[1]" typeHandler="customArrayHandler" />
<result property="arrayTwo" column="array[2]" typeHandler="customArrayHandler" />
Then in your CustomArrayHandler.getResult() implementation, you can parse the real column name and index out. Then retrieve the array from the ResultSet and get the needed value from the index.
That would require a lot of Oracle specific code in Mybatis and I know they have tried to avoid RDMS specific code in general. I would write your own data mappers to map the arrays to whatever model objects you need.

Resources