XPages getEffectiveUserName() - java

I'm using an XPage as an agent (XAgent) which makes an SSJS call into some Java classes stored as Java design elements. I want the processes which are instigated by the XPage to be in the context of the user I'm currently signed into the browser as. However everything seems to be running as me, I guess based on the last signature on the XPage?
For example, in my custom classes the following returns my name when I need it to be returning the user's name:
DominoUtils.getCurrentSession().getEffectiveUserName()
When using old school Domino agents, the effective username is determined by the "Run as Web User" or "Run on behalf of" fields in the agent properties.
Is it possible to achieve the same functionality when using an XPage?

To investigate you have a number of moving parts:
Add to the XAgent (not your Java code) a print statement with session.getUserName() and session.getEffectiveUsername()
Check your DominoUtils if there is a sessionAsSigner hidden in it
if 1 works, but not 3, consider dependency injection: instead of getting the session from DominoUtils hand it over as parameter from the XAgent to the Java class
Let us know how it goes

In my scenarios I could solve most of the requirements with either:
session.getEffectiveUserName()
or:
context.getUser().getFullName()
There are situations where you need to encapsulate this with:
session.createName(string):NotesName
to get the NotesName-Object representation.

Related

Is it possible to modify experiment parameter values after a model is run?

I'm following the Integrating AnyLogic Models with External Java Applications module and while I am able to change parameters before I run the exported java application, it seems the values become immutable once the model runs. Is there a way to dynamically modify parameter values at runtime?
Below is a snippet of my Java code:
final Simulation s = new Simulation();
IExperimentHost host = new ExperimentHost(s);
s.parameter1 = 50;
s.setup(host);
host.launch();
s.runTheModel();
s.parameter1 = 100;
The result is that parameter1 never changes from 50 to 100. Is there a way to circumvent this?
Try set_parameter. The help menu talks about this a little bit.
Edit:
Your original question was not directly linked to running as an external java application, but I think this could really simplify things. When you export your java application, look at the .bat file. You will see what the command line would look like to run the model. What we do when we are running from an external application is just have the external application call this command line, as opposed to what AnyLogic discusses in the help menu. A significant advantage of this is that you can easily mimic in the development environment what is going on in the exported model.
Ask your self why you are changing these parameters at runtime. Is it because of a read statement and you just don't have the data prior to the model run? If so, think about the order you instantiate your objects and don't start them until after you have the variables set that you want to use. This can be done by passing in parameters to main, setting database values, or having the main agent do various read statements.
Is it that you just want items to change over time? If so, consider variables, instead of parameters. Consider other objects that may allow you to more easily change flow. For example, does a valve before a pipeline or other sequence give you the level of control that you want?
At this point, would probably need more detailed information about what you are trying to accomplish / the system you are modeling, in order to provide any more specific advice.

A table that contains View objects tags

First of all I must say I'm new to both Android dev and Java.
I'm trying to find a list of the tags that are used for logging in Android studio.
The examples I've been researching include using:
Log.i(tag:"Info","message");
Log.i(tag:"Values","another message");
Log.i(tag:"Seekbar changed", "and another message");
I tried for the past couple of hours to find a document online, that has a table to describe the reserved tags for View objects, any help will be appreciated.
There is no fixed list of "reserved tags" one can use for logging in Android. You decide for yourself which tags you want to use and what additional information about the state of your objects or primitive types you want to display.
The Log class has six different log levels (debug, error, info, verbose, warn and wtf [What a Terrible Failure]) and corresponding (static) methods (Log.d, Log.e, Log.i, Log.v, Log.w and Log.wtf) each of which you call with two string parameters, one string parameter and one Throwable or two string parameters and one Throwable.
The most commonly used is probably the variant with two string parameters, one parameter for a tag (chosen by you) and one parameter for a message (also chosen by you). See this post for information about which level to choose.
During debugging I often use commands like this one:
Log.e(String.valueOf(myIntVariable), String.valueOf(myOtherVariable));
Let me explain the reason for using the Log class like this. I use the error level because it will give you red entries in the LogCat output (inside an IDE, e.g. Android Studio), and the same IDE will also let you filter out all logs below the error level. However, this is for debugging only; make sure to get rid of those log commands before your app enters production.
Instead of using logs in the way I do, you can also use breakpoints in the debug mode. I guess it is mainly a question of taste if you prefer one or the other. Toasts would be third option (with more boilerplate though).
If you use logs a lot in your code, it makes sense to use real tags. Either you define a string called TAG (or something else) in your class, or you put the name of the containing method as the first parameter. This will give you a sense of the order by which your methods are being called. You can also use other tags as well, and it doesn't have to follow a specific convention either (though you should have a system for it to make sense of it).

Multipage environment in GWT

I have been developing an AJAX web application using GWT. I've read several blogs and forums about this question and left with no clear idea. I understand that GWT is an AJAX application, that supports only stand-alone web application. By stand-alone, I meant GWT to be a single web page that would suffice the user requirements. However the use case I have is pretty complex and I'm stuck in this use case that doesn't let me proceed.
My usecase(s) goes like this:
Usecase #1: There is an order entry form where user will enter a search string to search for a particular item. With GWT, I could display the result in a table (say celltable). However, when I click a column in the cellTable, I want the value of the column to be sent to the server and display another page that will display only the details of the selected column. I'm not sure how to accomplish this.
Usecase #2: Let's say the web application I develop is called "InventoryControl" and I have different requirements such as:
display Available stock
display Order stock
display Manufactured unit
and Using Java servlets, I could just type http://localhost/availableStock?stockId=1234 on my browser to get the "Display available stock" for the given stockId and then http://localhost:orderStock?stockId=1234 to get the "display order stock" and similarly "display manufactured unit". Is the same possible using GWT? i.e. when I type http://localhost/availableStock?stockId=1234, is it possible to read the parameter being passed and then display the corresponding page?
If these are not meant to be guaranteed by GWT, should I stick with Plain old JAVA servlets/JSP?
Thanks in advance.
Ashok - Please note, what filip suggests above does not require multiple "pages" in the sense of additional html host pages. You can build a panel holding your display of the details, and swap it into the rootpanel of your host in the onSuccess() of your rpc call. The GWT history mechanism allows you to assign anchors to these "places" and provide a mechanism to map these anchors to specific display classes in your code.
GWT already has a mechanism for handling multiple page applications. Have a look at Activities and Places. You can define each page as a place in your application, and use the GWT mechanism to go from place to place at any time. Using places also allows you to easily add tokens/query parameters to each "page", in an OO manner, without having to worry about populating/querying the URL directly. Have a good read of the link!

Migration from WLI to Human workflow

while migration from weblogic WLI worflow to BPEL Human workflow, what is the option we have for jcx file for interacting with database.
any one please refer any document...
example; in my existing application we are selecting some values from database, in BPEL how we will achieve the same..
I am begineer in BPEL..
I have created a BPEL proces and data adapter inside that, now i want to execute that data adapter from my custom java code, is there any way to do the same.. pelase guide...
thanks
What versions are you working with? It is useful if you add more details about your set up.
Taking a wild guess, here is something that might help you:
Controls are exported as partner-links. The operations for this partner-link are derived from the methods in the control JCX file. Each method parameter is treated as a separate input message part; the name of the part is the same as the name of the parameter. The output message is determined from the return type of the control method. It has a single part called parameters, since a method has a single return type with no name.
http://download.oracle.com/docs/cd/E13214_01/wli/docs85/bpel/export.html#1061022
EDIT:
After a bit of research, I understand that you are on WLI 8.x. The link above should help you if you are facing problems exporting your JPD.
The alternate approach would be to import your 8.x project to 10g3 project, and export it from there. In this approach, you can generate BPEL2.0 compliant workflows. Warning: this is a one-time import, and the project will not be accessible via earlier WLI versions. So, try on a copy.
The second part of your question is not clear. Invoking controls from your Java code would be the same as invoking a web service. The WLI controls that are EJB calls/transformations get converted into web service portTypes. You can consume these web services from your Java application (eg., using Axis.)
Eg: If I am trying to convert a JPD SomeWorkflow.jpd, and if my JPD (WLI 8.x) had a control
/**
* #common:control
*/
private com.appmills.someapp.controls.TestDBCtrl dbctrl;
Or, alternatively with 10g3
#Control()
private com.appmills.someapp.controls.TestDBCtrl dbctrl;
The export creates three files SomeWorkflow.bpel, SomeWorkflow.wsdl and SomeWorkflow_ctrl.wsdl
The generated code would be:
<plnk:partnerLinkType name="com.appmills.someapp.controls.TestDBCtrl">
<plnk:role name="control">
<plnk:portType name="ctrl:com.appmills.someapp.controls.TestDBCtrlPT"
xmlns:ctrl="http://www.bea.com/workshop/bpel/ctrl"/>
</plnk:role>
</plnk:partnerLinkType>
EDIT 2:
The generated WSDL for controls (in the above example SomeWorkflow_ctrl.wsdl) does not contain <binding> or <service> tags. These are left out for you to define. The assumption is that you have these available somewhere, and have to simply wire them in.
As you might be aware of, the JCX equivalents in Oracle-SOA are JCAs. There is no direct export-import between WLI and Oracle-SOA. This means that there could be varying amount of efforts based on your current code complexity and your migration plan.
In my opinion, for JDBC Controls specifically, the simplest solution is to rewrite them as Database adapters.

Overriding PropertyMessageResources in struts 1, connecting to the request

I have a Struts 1 application using standard Struts internationalization, with a property file and everything. I need to change a specific message for only a select group of users, so I want to extend PropertyMessageResources. However, I can't find a way to connect the current request (so that I know whether it's one of those select users) to the message lookup.
1) Is there a better way to get this functionality? I thought about putting logic in the jsp's, but that doesn't get some situations, like messages obtained through the validator.
2) Is there a possible way to connect the request to the various getMessage() methods of my extended PropertyMessageResources object?
Here's what I ended up doing:
In the login script, check if it's one of the select users, and add a special String to the Variant part of their Locale, and put it in the session as their locale.
request.getSession(true).setAttribute("org.apache.struts.action.LOCALE", new Locale(locale.getLanguage(), locale.getCountry(), customVariant);
In the overridden PropertyMessageResources class, in the getMessage(Locale,String) method, just check the locale passed in to see if it has the special variant. I made all my custom variants start with a "_", and I check the first character of the variant before looking it up (so as to not slow down other users).
If anyone has a better solution, please post it.

Categories