ART#211 - How to query ATG Repository using dyn/admin ?





There might be some scenarios where you'd like to see/update/create data in the repository, and you do not want to write tedious database queries involving table joins and all that complex stuff.
Plus, when using database queries, you may not be able to visualize the data into an object manner and you also need to remember your schema names and database connection details (a lot of work..!). 
To save you from all that pain, headache and time-wastage, dyn/admin comes to the rescue. All you have to do is, browse for a Repository which you want to query in dyn/admin and fire an RQL query (which we studied in the previous article).

Let us see how!

Before we do anything, we have to open the dyn/admin, which opens using the URL:-

1. http://<your_url>:<port_on_which_your_app_server_is_running>/dyn/admin
2. Once, you open the dyn/admin. You click on "Component Browser" link.

3. A new page would open.
4. Next, click on search button.
5. Type the name of your repository and press ENTER.


6. You would see the search results, with your repository listed.
7. Click on the Link in the results.
8. Your repository opens, scroll down to see a text-area with "ENTER" button.
9. You write all your requests here.



1. Read the data

If you want to read the data, you require the name of the item-descriptor with one of the following:-

a. repository-id of the item: You need to have the repository-id of the item you want to fetch.
You can simply use a print-item tag for seeing the data in this case. 
See below screenshot:-


Once you follow the above steps, the page will reload and display the repository item corresponding to that ID.
The result looks somewhat like:-


The above screenshot displays all the details present for the user with ID "6610000".

NOTE: Please note that, if some property is set to its default JAVA value, the property will not display here. Examples of some values for which the property will not display:-
String - null
Any Object - null
boolean - false [if you override the default value to true in repository XML, the value properties with value "true" will not display]
etc.

OR

b. RQLs: If you do not have the repository-id of the item you are seeking, you have to write an RQL which would fetch all the items of the given item-descriptor based on the RQL.

For using RQLs, you need to use the <query-items> tag. The RQL must be enclosed within the <query-items> tag.
This would return all repository items for the given item-descriptor, which satisfy the condition in the RQL. See below screenshot for details:-



This will display ALL the items of type "user" which have more than one value in "creditCards" property. [This property is a List].
You can replace this RQL with any valid RQL we learnt in the previous chapter.

2. Creating/Adding the data.

This one is pretty much easy and can be achieved using <add-item> tags.
All you need to know is the name of the item-descriptor for which you want to add an item and a list of all the required properties of that item-descriptor.

a. find required properties of the item-descriptor
Open dyn/admin and navigate to your repository (As per the process mentioned above).
You will see a list of item-descriptors on the repository page. Against each item-descriptor, there will be a link "See property descriptions". [See below screenshot]



Click on this link, and a new page will open, with a table of all the properties of this item-descriptor, with first column as "name", which specifies the name of a property of this item-descriptor and last column as "required", which displays a boolean value of whether this property is mandatory or not.



b. add item to the repository
Now, once you know all the required properties, you can user <add-item> tags to insert items into the repository.
It starts with
1. Use an <add-item> tag, and specify the item-descriptor name.
You can also specify an "id" for the item you are creating. This is optional, so you can leave it and repository will generate an id for this item.

You can use <property> tags to set properties of an item. 
These can be strings, booleans, repository-item (in this case you have to specify the repository-id of the item you are referencing), list, set, map etc.
Lists/Sets and Maps, can in turn have strings/booleans or repository-items (again, you have to specify repository-id in this case).

2. All the required properties MUST be present between the <add-item> tags. If any one of them is missed, the item will not be created. You can also have non-required properties if you wish.

3. Finally, press Enter to add this item to the repository.

If done correctly, you will see the results like below.

3. Update existing item

To update an item, you must have a repository-id of the item you want to update.
If you do not have that, you can use RQLs to fetch the item (as mentioned in 1. Read the data), and when you see your desired item, you can copy the repository-id.

Now, updating an item is very much similar to <add-item>. 
You can do that in the following way.

1. Copy-paste the <add-item> tags
2. Replace <add-item with <update-item
3. Remove all the properties you DO NOT want to update and keep only the properties you want to update.
4. Press ENTER.

Your item will be updated and you'll get a message similar to the one in <add-item>.
Please note that, you do not require all the required properties to be present in the <update-item> tags because you are updating an existing item, and since the item already exists, it already has all the required properties. Therefore, you just have to specify the properties you want to update.

Now that we can use dyn/admin to our advantage, we will move on and understand how can we write Java code to do the actions we did from dyn/admin.


Back



Next






3 comments:

  1. ASAk..

    Thanks for all Tutorials..

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. It helped me using
    When adding a property

    ReplyDelete

Subscribe

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!

Flickr