A Division of Technology Associates International Corporation
Maximo Blog

How to upload a file for processing

June 16, 2009 in Maximo, Maximo 6, Maximo 7, Maximo: Programming by Michael Chrisman 15 Comments

Although the MIF/MEA is great for processing inbound files. However, sometimes they do not meet all your needs. For example, the MIF will require the user to have access to a folder on the server (a security problem). The MIF is also design for automated data import. Sometime you need to allow for the one-off, user managed data import. It is possible, through a dialog box on an app screen to import and process a file using a DataBean.

The first step is to create your dialog box (see How to Create a Dialog box). As it turns out, there is a Maximo control for the file upload control. The issue is that it is not one the control pallet. What you have to do it edit a screen that uses the control (like External System) and copy the XML for the control. Or you can just use the following code wink

   1:          <buttongroup id="load_2222">
   2:              <uploadfile cancellabel="Cancel" event="loadData" id="importfile_file_2_1" label="Specify Import File" maxfilesize="200" oklabel="OK"/>
   3:          buttongroup>

Add this code (by editing the XML) to you dialog box. You can just have this as the only thing on the dialog box if you want. You will notice that the event attribute is ‘loadData’. This is the name of the method you need to add to your DataBean. In your method, add the following code:

   1:      public int loadData() throws NumberFormatException, MXException, RemoteException
   2:      {
   3:          // setup some variables. 
   4:          ByteArrayInputStream btIn;
   5:          javax.servlet.http.HttpServletRequest request;
   6:          String fName;
   7:          MPFormData mpData = null;
   8:          btIn = null;
   9:          request = clientSession.getRequest();
  10:          fName = null;
  11:          WebClientEvent wce = clientSession.getCurrentEvent();
  12:          ControlInstance uploadfileControl = wce.getSourceControlInstance();
  13:          String maxfilesize = uploadfileControl.getProperty("maxfilesize");
  14:          mpData = new MPFormData(request, Integer.parseInt(maxfilesize));
  15:          fName = mpData.getFileName();
  16:          
  17:          // check to make sure the file name exists
  18:          if(fName == null || fName.toUpperCase().equals("UNKNOWN"))
  19:          {
  20:              // TODO: the user did not select a file, so throw a MXAppliationException to display such a messgae
  21:          }
  22:   
  23:          byte fileBytes[] = mpData.getFileOutputStream().toByteArray();
  24:          btIn = new ByteArrayInputStream(fileBytes);
  25:   
  26:          // This is where we process the file. We read the file one character at a time.
  27:          int curIntChar; // this will be the current character we are processing
  28:          String currentLine = ""; // this will be a full line of data from the file.
  29:          int RetVal;
  30:          for (int i = 0; i < fileBytes.length; i++)
  31:          {
  32:              curIntChar = btIn.read();
  33:              if ((char) curIntChar == 'n') // check for a carrage return. You made need to modify this if you are loading a unix file.
  34:              {
  35:                  // TODO: add code here to process the line that is stored in 'currentline'
  36:                  currentLine = "";
  37:              }
  38:              else
  39:              {
  40:                  currentLine += (char) curIntChar;
  41:              }
  42:          }
  43:          // we are all done with the file, but we may have a line to process if the last line did not end in a carrage return.
  44:          if (currentLine.length()>0)
  45:          {
  46:              //TODO: process the line that is stored in 'currentline'
  47:          }
  48:          //ok, the file is processed
  49:   
  50:          // be kind and close the data stream.
  51:          try
  52:          {
  53:              if(btIn != null)
  54:                  btIn.close();
  55:          }
  56:          catch(Exception e)
  57:          {
  58:              e.printStackTrace();
  59:          }
  60:          return 1;
  61:      }

Now compile and test. This will allow you to upload and process any type of file you can read with Java.

 

Technorati Tags: ,,

Comments

David R.
Posted on October 18, 2009

Sadly, i am getting a resource not found after modify the app’s xml to include the buttongroup with the uploadfile tag.

Specifically:

<Include resource or file “/webclient/controls/uploadfile/control.jsp” not found from requested resource “/ui/maximo.jsp”.

Am I sunk? Is there anything I can do at this point?

Michael Chrisman
Posted on October 30, 2009

David,

Make sure you that you have valid XML.

MikeC

David R.
Posted on November 05, 2009

Will re-check the xml..

However, I did a search for control.jsp and examined the list that was returned:

The list of subdirs is in alphabetical order, so I see:

yes is there—>  ..\webmodule\webclient\controls\treenode
not there :(—>  ..\webmodule\webclient\controls\uploadfile
yes there—>  ..\webmodule\webclient\controls\wallcalendar

Is there still hope that it’s an xml issue only?  Do you not have control.jsp in your world and the file txfr still works?

David R.
Posted on November 05, 2009

First of all, thanks for your help!

I copied the XML for the Data Import dialog from EXTSYS and into XL (my app).  Within that I gutted all sections / button groups and inserted the buttongroup as you describe in your article. 

However, what about the dialog as it’s constructed? Do I need to change the bean class?  Here’s how it looks now:

<dialog id=“load” label “Data Import” mboname=“XL” beanclass=“psdi.webclient.beans.extsystem.LoadBean” >

Michael Chrisman
Posted on November 05, 2009

David,

I just realized something. Why are you modifing control.jsp for this? You need to the add the <dialog..> to the XML of the screen you want it to be part of. That is done in the Application Designer screen. This code only works for Maximo 6 and 7.

MikeC

David R.
Posted on November 05, 2009

Sorry - I wasn’t clear, retry:

In App Designer I add the XML to create a dialog that includes the buttongroup with the tag “<uploadfile cancellabel=“Cancel” event=“loadData”...

Near as I can figure, the <uploadfile tag triggers some kind of call to the \webmodule\webclient\controls\uploadfile\control.jsp, I’m assuming to load the control to allow one to select a file. 

Do you have a subdir/file “\webmodule\webclient\controls\uploadfile\control.jsp” in your instance of maximo, by chance?  The idea isn’t to modify that control, but apparently I need it….

* sigh *

TIA, Dave

David R.
Posted on November 09, 2009

Can’t tell whether my response from last week ‘made it’ onto this site - I apologize if this is a dupe:

Your post is excellent - I feel like I’m really close. 

I do have Maximo 6.2.  I’m not modifying control.jsp.  Instead, it appears that, when maximo encounters the tag:

“<uploadfile cancellabel=“Cancel” event=“loadData” ...”

in the xml of the application, maximo tries to verify that the control.jsp exists in the folder:

“..\webmodule\webclient\controls\uploadfile\control.jsp”

and, if it doesn’t, an error is thrown. 

It appears my install of maximo doesn’t include the necessary files. 

I also don’t have a ControlInstance.class file, referred to in..

“ControlInstance uploadfileControl = wce.getSourceControlInstance…”

The burst of hope and optimism I experienced when I first read thru your posting is fading somewhat.  Would you say I’m sunk? 

Thanks again for taking time to respond.

Michael Chrisman
Posted on November 09, 2009

David,

Very strange. I am not sure how to help. Sorry I can’t be more help.

MikeC

David R.
Posted on November 09, 2009

Thanks anyway.  I was reading something over the weekend that said something like the MEA needs to be installed (MDB’s).  Apparently there’s a configuration file that needs to be modified (maximo is running on weblogic).  Maybe tending to that will have a positive impact. 

If I can’t upload the file for processing, I think I’ll just write an outside application that renders the file in xml format.  Then, in maximo, I’ll create an app with a clob field and a button, then instruct user to copy and paste the xml rendition of the file into the clob field and click the button to process it. 

Appreciate your input nonetheless!

- Dave

David R.
Posted on November 12, 2009

One thing I think you can do for me, if you don’t mind:

Can you check to see whether you have an ‘uploadfile’ subdirectory with control.jsp within it:

“\webmodule\webclient\controls\uploadfile\control.jsp”

If you do and I don’t, then I need look no further - my install of maximo is missing stuff…

Michael Chrisman
Posted on November 16, 2009

David,

My version of Maximo does not have that folder, but it does have the MEA installed.

MikeC

Nandu Jalumuri
Posted on February 02, 2010

Please modify the Hyperlink (see How to Create a Dialog box)in your post from

http://www.taic-sams.net/blog/article/how-to-create-a-dialog-box/

to

http://sams.taic.net/index.php/blog/article/how-to-create-a-dialog-box/

Regards,
Nandu J

Michael Chrisman
Posted on February 24, 2010

Nandu,

Thanks for point this out. The blog host recently moved the site to a new server and ended up changing the url. All links still work if you change the server from http://www.taic-sams.net/blog/... to http://www.taic-sams.net/index.php/blog/...

MikeC

jeda
Posted on March 27, 2010

Anyone solve the following issue, am getting the same error.

Sadly, i am getting a resource not found after modify the app’s xml to include the buttongroup with the uploadfile tag. Specifically:<Include resource or file “/webclient/controls/uploadfile/control.jsp” not found from requested resource “/ui/maximo.jsp”.

jeda
Posted on May 11, 2010

Note, this only works in Maximo 7, not Maximo 6.  The Include resource or file “/webclient/controls/uploadfile/control.jsp” not found error is from Maximo 6.

Post a Comment

Remember my personal information.
Notify me of follow-up comments?

We don't know if you're a human. Confirm below: