How to add custom property to data source with Jython? - jython

We are using Jython to configure a data source in WAS. The data source created OK, with some default custom properties. Now I need to add another property, without deleting the other propertues. Any ideas?

You can follow the instructions on the Knowledge Center link below to create a new data source custom property using Jython:
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-nd-dist&topic=txml_configcustom
The link provides the following steps:
Identify the parent ID:
newds = AdminConfig.getid('/Cell:mycell/Node:mynode/JDBCProvider:JDBC1/DataSource:DS1/')
print newds
Example output:
DS1(cells/mycell/nodes/mynode|resources.xml$DataSource_1)
Get the J2EE resource property set:
propSet = AdminConfig.showAttribute(newds, 'propertySet')
print propSet
Example output:
(cells/mycell/nodes/mynode|resources.xml#J2EEResourcePropertySet_8)
Get required attribute:
print AdminConfig.required('J2EEResourceProperty')
Example output:
Attribute Type
name String
Set up attributes:
name = ['name', 'RP4']
rpAttrs = [name]
Create a J2EE resource property:
print AdminConfig.create('J2EEResourceProperty', propSet, rpAttrs)
Example output:
RP4(cells/mycell/nodes/mynode|resources.xml#J2EEResourceProperty_8)
Save the configuration changes.
In a network deployment environment only, synchronize the node.

Related

create nodes programatically with gmf but without setting its properties

I want to create nodes programatically with its properties but using the folowing codes nodes can be created but its properties can not be set.
CreateUnspecifiedTypeRequest request_ch = new
CreateUnspecifiedTypeRequest(
Collections.singletonList(xxxElementTypes.yy),
diagramEditPart.getDiagramPreferencesHint());
Command command = diagramEditPart.getCommand(request);
command.execute();
then element.set("idof element") but the properties of the node still empty.
may someone help me .thanks
I am currently using this method in order to create nodes programatically. The node and the properties appear just fine and you can edit them. (note that there is also a way to edit the properties programmatically, with another type of command (EMF))
public void createAndExecuteShapeRequestCommand(IElementType type, EditPart parent) {
CreateViewRequest actionRequest = CreateViewRequestFactory
.getCreateShapeRequest(
type,
PreferencesHint.USE_DEFAULTS);
org.eclipse.gef.commands.Command command = parent.getCommand(actionRequest);
command.execute();
}
A sample caller of that method if the node is meant to be added in the main area of the diagram.
createAndExecuteShapeRequestCommand(xxx.diagram.providers.xxxElementTypes.ELEMENT_HERE, diagramEditPart);
A sample caller of that method if the node is meant to be added inside another node or compartment.
DiagramEditPart diagramEditPart = getDiagramEditPart(); //diagram.getDiagramEditPart();
"ParentElement" parentElement = (("Root_ELEMENT") diagramEditPart.resolveSemanticElement())."getTheElement"();
List list = getDiagramGraphicalViewer().findEditPartsForElement(EMFCoreUtil.
getProxyID(parentElement),
TheElementsEDITPART.class);
createAndExecuteShapeRequestCommand(xxx.diagram.providers.xxxElementTypes.ELEMENT_HERE, (EditPart)list.get(0));
Note that, if you wish to call this method from other class than the one of the xxxDiagramEditor.java you will need somehow to pass there the diagramEditPart.

Adding a new attribute to an Object Class and Expecting it to automatically show up in existing objects in Apache DS

I am working on a use case where I have to dynamically add a new attribute to an existing object class in Apache DS.
1)Here is some code which defines my object class:--
Attributes attrs = new BasicAttributes(true);
attrs.put("NUMERICOID", "1.3.6.1.4.1.18060.0.4.3.3.1");
attrs.put("NAME", "ship");
attrs.put("DESC", "An entry which represents a ship");
attrs.put("SUP", "top");
attrs.put("STRUCTURAL", "true");
Attribute must = new BasicAttribute("MUST");
must.add("cn");
attrs.put(must);
Attribute may = new BasicAttribute("MAY");
may.add("numberOfGuns");
may.add("numberOfGuns2");
may.add("description");
attrs.put(may);
//add
schema.createSubcontext("ClassDefinition/ship", attrs);
2) Adding an object of that object class:
Attributes attributes=new BasicAttributes();
Attribute objectClass=new BasicAttribute("objectClass");
objectClass.add("ship");
attributes.put(objectClass);
Attribute g=new BasicAttribute("numberOfGuns");
Attribute g2=new BasicAttribute("numberOfGuns2");
Attribute cn=new BasicAttribute("cn");
g.add("2");
g2.add("3");
cn.add("four");
attributes.put(g);
attributes.put(cn);
attributes.put(g2);
;
ctx.createSubcontext("cn=four,dc=example,dc=com",attributes);
3) Add a new attribute -- 'mustA' to the object class
Attributes attrs = new BasicAttributes(true);
attrs.put("NUMERICOID", "1.3.6.1.4.1.18060.0.4.3.3.1");
attrs.put("NAME", "ship");
attrs.put("DESC", "An entry which represents a ship");
attrs.put("SUP", "top");
attrs.put("STRUCTURAL", "true");
Attribute must = new BasicAttribute("MUST");
must.add("cn");
must.add("mustA");
attrs.put(must);
Attribute may = new BasicAttribute("MAY");
may.add("numberOfGuns");
may.add("numberOfGuns2");
may.add("description");
attrs.put(may);
//modify
schema.modifyAttributes("ClassDefinition/ship",DirContext.ADD_ATTRIBUTE ,attrs);
Once the new attribute is added(which means object class is modified), If i add a new object of that object class type, I can see the newly added attribute in the newly created object.
My Question is, What happens to the objects which were created before I added the new attribute? How can I make the new attribute to show up in the exiting objects automatically? For example, here will the new attribute "mustA" automatically show up in object "four"?
Or Will I have to manually go and modify that object to add that new attribute?
You will need to update the schema. For ApacheDS the easiest method is to download Apache Studio and take a look at 2.3.1 - Adding Schema Elements
Oh, and you will always get great support from The Directory Users List for ApacheDS. The developers are very active.
AFIK, ApacheDs will support adding schema from LDAP calls, but I am not positive. (See The Directory Users List for ApacheDS)
If you insist doing this the hard way, check out the examples at:
http://docs.oracle.com/javase/jndi/tutorial/ldap/schema/object.html
-jim

How to access key-value Lookup through the API in GoodData?

In GoodData's ETL tool there's a key-value store that one can use for keeping some kind of state between ETL runs: http://developer.gooddata.com/cloudconnect/manual/lookup-table-functions-ctl2.html
Is there a way how to set / read these values through the REST API?
There is something called project metadata. It holds metadata on a per project level. It is what you can see if you go to Project explorer in CloudConnect and look at customer properties.
The data can be read like this
GET /gdc/projects/<projectName>/dataload/metadata
You can read only particular key
GET /gdc/projects/<projectName>/dataload/metadata/<key>
And update an existing key
PUT /gdc/projects/<projectName>/dataload/metadata/<key>
Also delete
DELETE /gdc/projects/<projectName>/dataload/metadata/<key>
Or create a new on
POST /gdc/projects/<projectName>/dataload/metadata/ {"metadataItem" : {"key" : "some_key", "val" : "some_val"}}
Another way is to use GoodData ruby SDK (https://github.com/gooddata/gooddata-ruby/)
client = GoodData.connect('username', 'pass')
project = client.projects('project_id')
project.metadata
metadata.inspect
You can also set the metadata liek this
project.set_metadata('key', 'val')

Wsapi data store query

I am looking to get all projects under a selected project (i.e the entire child project branch ) using Wsapi data store query in Rally SDK 2.0rc1. Is it possible using a query to recursively get all child project names? or will I have to write a separate recursive function to get that information? If a separate recursive function is required, how should I populate that data into for example, a combo box? Do I need to create a separate data store and push the data from my recursive function in it and then link the Combobox's store to it?
Also, how to get the "current workspace name" (workspace that I am working in, inside Rally), in Rally SDK 2.0rc1 ?
Use the 'context' config option to specify which project level to start at and add 'projectScopeDown' to make sure child projects are returned. That would look something like this:
Ext.create('Rally.data.WsapiDataStore', {
limit : Infinity,
model : 'Project',
fetch : ['Name','ObjectID'],
context : {
project : '/project/' + PROJECT_OID,
projectScopeDown : true
}
}).load({
callback: function(store) {
//Use project store data here
}
});
To get your current context data, use: this.getContext().
var workspace = this.getContext().getWorkspace();
var project = this.getContext().getProject();
If you try exposing with console.log the this.getContext().getWorkspace() and this.getContext().getProject() you may understand better what is returned and what is required. In one of my cases I had to use this.getContext().getProject().project.
Using console debug statement is best way to figure what you need based on its usage.

NHibernate - How do I change schemas during run time?

I'm using NHibernate to connect to an ERP database on our DB2 server. We have a test schema and a production schema. Both schemas have the same table structure underneath. For testing, I would like to use the same mapping classes but point NHibernate to the test environment when needed and then back when in production. Please keep in mind that we have many production schemas and each production schema has an equivalent test schema.
I know that my XML mapping file has a schema property inside it, but since it's in XML, it's not like I can change it via a compiler directive or change the schema property based on a config file.
Any ideas?
Thank You.
No need to specify schema in the mappings: there's a SessionFactory-level setting called default_schema. However, you can't change it at runtime, as NHibernate pregenerates and/or caches SQL queries, including the schema part.
To get what I wanted, I had to use NHibernate.Mapping.Attributes.
[NHibernate.Mapping.Attributes.Class(0, Table = “MyTable”, Schema = MySchemaConfiguration.MySchema)]
In this way, I can create a class like MySchemaConfiguration and have a property inside of it like MySchema. I can either set the property's value via a compiler directive or get it through a configuration file. This way I only have to change the schema in one place and it will be reflected throughout all of the other mappings.
I have found following link that actually fixes the problem.
How to set database schema for namespace in nhibernate
The sample code could be
cfg.ClassMappings.Where(cm => cm.Table.Schema == "SchemaName")
.ForEach(cm => cm.Table.Schema = "AnotherSchemaName");
This should happen before you initialize your own data service class.
#Brian, I tried NHibernate.Mapping.Attributes, the attribute value you put inside should be a constant. So it could not be updated during run time. How could you have set the property's value using a parameter value in configuration file?
The code to fix HBM XML resources.
// This is how you get all the hbm resource names.
private static IList<string> GetAllHbmXmlResourceNames(Assembly assembly)
{
var result = new List<string>();
foreach (var resource in assembly.GetManifestResourceNames())
{
if (resource.EndsWith(".hbm.xml"))
{
result.Add(resource);
}
}
return result;
}
// This is how you get the stream for each resource.
Assembly.Load(assembly).GetManifestResourceStream(name)
// What you need to do next is to fix schema name in this stream
// Replacing schema name.
private Stream FixSchemaNameInStream(Stream stream)
{
StreamReader strStream = new StreamReader(stream);
string strCfg = strStream.ReadToEnd();
strCfg = strCfg.Replace(string.Format("schema=\"{0}\"" , originalSchemaName), string.Format("schema=\"{0}\"" , newSchemaName));
return new MemoryStream(Encoding.ASCII.GetBytes(strCfg));
}
Take a look at SchemaUpdate.
http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/28/create-and-update-database-schema.aspx