Add new-item/data in ATG repository.

SQL Table:

atgrepo1

 

 

 

 

 

 

Repository in ATG:

atgrepo2

 

 

 

MyDataSource.properties:

$class=atg.nucleus.JNDIReference
JNDIName=<JNDI Name>

myrepo.properties:

$class=atg.adapter.gsa.GSARepository
$scope=global
XMLToolsFactory=/atg/dynamo/service/xml/XMLToolsFactory
dataSource=/com/mohitrepo/MyDataSource
definitionFiles=/com/mohitrepo/myRepo.xml
idGenerator=/atg/dynamo/service/IdGenerator
transactionManager=/atg/dynamo/transaction/TransactionManager
repositoryName=StoreRepository
checkTables=false
lockManager=/atg/dynamo/service/ClientLockManager
# Resource bundle name
#componentResourceBundleName=atg.projects.store.stores.StoreRepositoryResources
# Display name key
repositoryDisplayNameResource=storeRepositoryDisplayName

myrepo.xml

<!DOCTYPE gsa-template PUBLIC "-//Art Technology Group, Inc.//DTD Dynamo Security//EN" "http://www.atg.com/dtds/gsa/gsa_1.0.dtd">
<gsa-template>
 <header>
 <name>MyRepo Definition</name>
 <author>Mohit</author>
 </header>

 <item-descriptor name="myproduct">
 <table name="mohit_tab1" type="primary" id-column-name="name">
 <property name="name" column-names="name" data-type="string" />
 <property name="number" column-names="num" data-type="int" />
 </table>
</item-descriptor>
</gsa-template>

Droplet to insert data:

package com.mohit;
import java.io.IOException;
import javax.servlet.ServletException;
import atg.repository.MutableRepository;
import atg.repository.MutableRepositoryItem;
import atg.repository.RepositoryException;
import atg.servlet.DynamoHttpServletRequest;
import atg.servlet.DynamoHttpServletResponse;
import atg.servlet.DynamoServlet;
public class MutableRepositoryDroplet extends DynamoServlet{
 @Override
 public void service(final DynamoHttpServletRequest pReq,
 final DynamoHttpServletResponse pRes) throws ServletException,
 IOException {

 //receive repository name
 Object repository = pReq.getLocalParameter("repository");
 //receive item descriptor defined in repository XML file
 String itemDescriptor = (String) pReq.getLocalParameter("itemDescriptor");
 //receive values of columns defined under item descriptor 
 String name = (String) pReq.getLocalParameter("name");
 int number = Integer.parseInt((String)pReq.getLocalParameter("number")) ;

 if(repository == null){
 throw new ServletException("Missing repository parameter.");
 }

 MutableRepository mutableRepository = (MutableRepository) repository;
 MutableRepositoryItem mutableRepositoryItem = null;

 try {
 mutableRepositoryItem = mutableRepository.createItem(itemDescriptor);
 } catch (RepositoryException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }

 mutableRepositoryItem.setPropertyValue("name", name);
 mutableRepositoryItem.setPropertyValue("number", number);

 try {
 mutableRepository.addItem(mutableRepositoryItem);
 } catch (RepositoryException e) {
 e.printStackTrace();
 }

 pReq.setParameter("myresult", "Inserted value in DB.");
 pReq.serviceParameter("myoutput", pReq, pRes);

 }
}


Droplet property file - MutableRepositoryDroplet.properties
$class=com.mohit.MutableRepositoryDroplet

JSP:

<dsp:page>
<head>
<title>MutableRepositoryDroplet</title>
</head>
<body>
<dsp:droplet name="/com/mohit/MutableRepositoryDroplet">
 <dsp:param name="repository" bean="/com/mohitrepo/myrepo"/>
 <dsp:param name="itemDescriptor" value="myproduct"/>

 <dsp:param name="name" value="Jinnah"/>
 <dsp:param name="number" value="14"/>

 <dsp:oparam name="myoutput">
 <dsp:valueof param="myresult">No value</dsp:valueof>
 </dsp:oparam>
</dsp:droplet>
</body>
</dsp:page>