The Kat's Work - Blog
Main | Blog | Registration | Login
Friday
2024-05-17
3:20 AM
Welcome Guest | RSS

Crystal is good, however generally to run any reports you need at least the report viewer installed on someone’s pc. That sucks! So here is how to make a distributable jar file that when clicked will run a crystal report without the need for other installed software.

First off you need to install the Crystal Reports for Eclipse plugin into Eclipse. Instructions and download can be found here http://www.sdn.sap.com/irj/sdn/crystalreports-java however SAP has an annoying habit of moving their pages about 7 times a month.

Okay Dokey, so you now have crystal reports abilities in eclipse. The nice chaps at SAP provide this plug in free of charge and only ask that it not be resold. So fell free to use it but don’t make it part of something you intend to sell commercially, or you’ll have to buy a licence.

You can now add Crystal reports to existing webapps (which I’ll tutorial later), and also more importantly for this tutorial make standalone "jarrable” crystal reports applications.

In Eclipse go to file -> New -> other. Select folder "Crystal Reports” than Crystal Reports Java Project. Call it something meaningful. Press finish.

You now have a working java application that can run Crystal reports, well done.

At this point we can just jar this up and run it. Right Click the project click Export….
Go to Java folder choose runable jar file. Click Next. The sample project already has launch configurations set up so in the box choose SampleViewerFrameClient, than choose where you want the jar to go.

You now have a run anywhere crystal report viewer. This jar when run will ask you which report you wish to run. Find the report you want and run hoorah!……That’s not what we want though, we want a user to click this report and a particular report to be run. Further we want the report to be bundled into the library (jar) for distribution.

So now we want to set up the application to just choose the report we want and also to include this file in the jar. To include the report in the jar you must add it to the src folder. Eclipse when making a runnable jar is quite selective on what it exports. You can make it export more than the src folder but you’ll have difficulties referencing the report if it is anywhere other than the src folder.

So with added the report to src folder. Now open the report in eclipse. The connection for the report must be jdbc. If it is not you must change it, remembering to include any needed external libraries (i.e jtds) into the project build path.

Now the coding. The sampleViewerFrame class has almost everything we need. So lets copy it. Rename the copy something meaningful. First off you’ll need to add a new private function as below.

  private void loadPreSetReport()throws ReportSDKException{
   
      
       
        reportClientDocument = new ReportClientDocument ();
        reportClientDocument.setReportAppServer(ReportClientDocument.inprocConnectionString);
        reportClientDocument.open ("<YourReport.rpt>", OpenReportOptions._openAsReadOnly);
       
       
    }

This function will replace the LoadReport function. So next we need to replace the reference to loadReport() with loadPreSetReport() in function showReport.

Next we need to copy the SampleViewerFrameClient class. This will prevent us having to recreate the launch Configuration. Name it something meaningful. Replace its static reference to SampleViwerFrame with your version.

Optional part, you can preset login values in the Frame class. Simply open your version of SampleViewerFrame go to function setDatabaseLogon and uncomment line

CRJavaHelper.logonDataSource (reportClientDocument, "username", "password");

Replace username and password as necessary. Be warned though this will make your report run able by anyone who acquires your jar file.

Right Click the project click Export….
Goto Java folder choose runable jar file. Click Next. Choose your custom version of SampleViewerFrameClient, than choose where you want the jar to go.

Congratulations you now have a single file containing a "portable” version of the report.

Views: 63221 | Added by: The_Kat | Date: 2010-12-17 | Comments (11)




Just a qick update on the attempt to implement MVC in lotus script. Its going  pretty well, with a bear minimum of shouting to the gods of Coding to smite IBM down.

I quickly identified the benefit of replicating (stealing) the get/set methodology of other frame works. This way you can really control the business logic around setting particular field values. The downside? So many getters and setters…….

I think I will have to a some point write an eclipse plugin to generate these like it does for java. It also hasn’t helped I’ve taken the idea to include a clear method with the getters and setters. 50% more work, well done me. Unlike frameworks with a separate ui/database a lot of business logic in notes is to make the information display right in UI. So the clear functions are vital to maintain the functionality across the board. Some fields may be cleared by a document.replaceItemValue("field1”,””) while number fields need a 0 or custom functionality may require that clearing a field actually fills it with a default value. The addition of a clear function for all fields allows for tight control of this functionality.

I have also written a pretty nifty applications factory class that I will post at a later date.

Again here is a "brief example” of the Current Code this time focusing on Data access and Business Logic. Included is my master Entitymodel class. I have tried to make it a working example by removing all custom error handling. I apologise in advanced for anything I’ve missed/left in.

Public Class entityModel As entityCommons
    Private session As NotesSession
    Private document As NotesDocument
   
    Public Function atword(value As String, separator As String, occurance As Integer)
       
        Dim tmpString As String
        tmpString = value
        Dim i As Integer
        For i = 1 To occurance -1
                tmpString = Right(tmpString,Len(tmpString) - InStr(tmpString,separator))
        Next
        If(InStr(tmpstring,separator) > 0 )then
        tmpString = Left(tmpString,InStr(tmpString,separator)-1)
        End if
        atword = tmpString
       
    End Function
     
    Public Sub New()
        Set session = New NotesSession
       
    End Sub
   
   
    Public Sub save
       
        Call document.Save(True , False)
    End Sub
   
   
    Public Function getDocument() As NotesDocument
       
        Set getDocument = document
       
       
    End Function
   

    Private Function getItemValue(fieldName As String) As Variant
       
    getItemValue = document.Getitemvalue(fieldname)
       
    End Function

   
    Private Function setItemValue(fieldName As String,value As Variant)
           
        Call document.replaceItemValue(fieldName,value)
       
       
    End Function

   
   
    Private Function appendItemValue(fieldName As String,value As String, seperator As String)
                    Call document.replaceItemValue(fieldName,document.Getitemvalue(fieldname)(0) & seperator & value)
       
   
    End Function
   
   
    Private Function replaceItemValue(fieldName As String,value As String, seperator As String , element As Integer)
           
            Dim elements As Variant
            elements = Split(document.getItemValue(FieldName)(0),"#")
            elements(element) = value
        Call document.replaceItemValue(fieldName, Join(elements,"#"))
       
   
    End Function
   
   
   
    Private Function getItemValueElement(fieldname As String, seperator As String , element As Integer) As String
       
        getItemValueElement = atword(document.getItemValue(FieldName)(0),seperator,element)
       
   
    End Function
   
   
   

End Class

Public Class PersTable01Dao
    Private database As NotesDatabase
    Private view As NotesView
   
    Public Sub New()
   
       
        Set ApplicationFactory = New ApplicationFactory()
        Set database = ApplicationFactory.getApplication("Personnel - Tables", DATABASESTYPE)   
    End Sub
   
   
    Public Function getPersTable01(key As String) As PersTable01
        Set view = database.getView("PersTable03")
        Dim doc As NotesDocument

        Set doc = view.getDocumentByKey(key,true)   
        Dim PersTable01 As PersTable01
        Set PersTable01 = New PersTable01()
        Call PersTable01.setDocument(doc)
        Set getPersTable01 = PersTable01
       
    End Function
End Class

Public Class PersTable01 As entityModel
    Private database As NotesDatabase   
    Public Sub New(), entityModel()
       
       
       
    End Sub
   
   
   
    Public Sub newDocument(database As NotesDatabase)
        If database Is Nothing Then
            Set database = session.Currentdatabase
        End If
        Set document = database.CreateDocument
        document.form = "PersTable01"
    End Sub
   
    Public Sub setDocument(passedDocument As NotesDocument)
        Set document = passedDocument
       
    End Sub
   
   
    Public Function getTableEntry() As String
       
        getTableEntry =  getItemvalue("TableEntity")(0)       
    End Function
    Public Function getTable_User1() As String
       
        getTable_User1 =  getItemvalue("Table_User1")(0)       
    End Function
Public Function getTableEntry(value as string)
       
        Call setItemvalue("TableEntity”, value)       
    End Function
    Public Function getTable_User1() As String
       
        Call setItemvalue("Table_User1”, value)   
       
    End Function
Public Function clearTableEntry()
       
        Call setItemvalue("TableEntity”, "”)       
    End Function
    Public Function clearTable_User1() As String
       
        Call setItemvalue("Table_User1”, "No Value”)   
       
    End Function
    Private function onTableEntryChange()
        If(getTableEntry = "”) then
call    ClearTable_User1()
        End if
    End function
   
End Class
Views: 18068 | Added by: The_Kat | Date: 2010-12-07 | Comments (0)


I recently implemented error logging in a Java Struts application. The benefits of this are obvious but as this was an internal application, the customer has always accepted the error messages. Recently however its become harder to problem solve as users aren't capturing displayed stack traces correctly. SO to that end i implemented the code below to allow for the programatic logging of errors. The user is presented with a styled "Whoops" page and asked to try again.

The basic functionality is that the errorlog logs the time adn stack trace of the error. Also it logs the user (as the system requires login.) , the action they were performing and the parameters they(or the system) had specified.

In a later blog post i will adapt this to Java Spring.

Database structure.

Id    PK, int, not null
Error_time    Datetime, not null
Error_by    Int, null (FK to user table)
Exception_report    Text, not null
Action    Varchar(50), not null
parameters    Varchar(200), null)


import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.sql.Timestamp;

import com.project.objects.User;

public class ErrorLog {
    private Integer id;
    private Timestamp errorTime;
    private User errorBy;
    private String exceptionReport;
    private String action;
    private String parameters;
   
   
    /**
     * @return the id
     */
    public Integer getId() {
        return id;
    }
    /**
     * @param id the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }
    /**
     * @return the errorTime
     */
    public Timestamp getErrorTime() {
        return errorTime;
    }
    /**
     * @param errorTime the errorTime to set
     */
    public void setErrorTime(Timestamp errorTime) {
        this.errorTime = errorTime;
    }
    /**
     * @return the errorBy
     */
    public User getErrorBy() {
        return errorBy;
    }
    /**
     * @param errorBy the errorBy to set
     */
    public void setErrorBy(User errorBy) {
        this.errorBy = errorBy;
    }
    /**
     * @return the exceptionReport
     */
    public String getExceptionReport() {
        return exceptionReport;
    }
    /**
     * @param exceptionReport the exceptionReport to set
     */
    public void setExceptionReport(String exceptionReport) {
        this.exceptionReport = exceptionReport;
    }
    /**
     * @return the action
     */
    public String getAction() {
        return action;
    }
    /**
     * @param action the action to set
     */
    public void setAction(String action) {
        this.action = action;
    }
    /**
     * @return the parameters
     */
    public String getParameters() {
        return parameters;
    }
    /**
     * @param parameters the parameters to set
     */
    public void setParameters(String parameters) {
        this.parameters = parameters;
    }

   
     public void fillMessage(Throwable aThrowable) {
            final Writer result = new StringWriter();
            final PrintWriter printWriter = new
PrintWriter(result);
            aThrowable.printStackTrace(printWriter);
            this.setExceptionReport(result.toString());
     }

}

<hibernate-mapping>
<class name="com.projects.objects.errorLog.ErrorLog" table="ErrorLog">
  <id column="ID" name="id" type="int">
   <generator class="native"/>
  </id>
 <many-to-one class="com.project.objects.User"
   column="error_by" name="errorBy" />
    
    <property column="error_time" generated="never" lazy="false"
   name="errorTime" type="java.sql.Timestamp"/>
  <property column="exception_report" generated="never" lazy="false"
   name="exceptionReport" type="java.lang.String"/> 
 <property column="action" generated="never" lazy="false"
   name="action" type="java.lang.String"/> 
   <property column="parameters" generated="never" lazy="false"
   name="parameters" type="java.lang.String"/> 
</class>

</hibernate-mapping>

import java.util.List;

import com.project.objects.errorLog.ErrorLog;

public interface ErrorLogDao {

    public Integer saveObject(ErrorLog errorLog);
       
    public List<ErrorLog> getAllErrorLogs();
   
    public List<ErrorLog> getErrorLog(Integer id);
   

   
}

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.project.hibernate.HibernateUtil;
import com.project.dao.ErrorLogDao;
import com.project.objects.errorLog.ErrorLog;

public class ErrorLogDaoHibernate implements ErrorLogDao{
    /**
     *
     */
    public ErrorLogDaoHibernate() {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    public Session session = null;
    public Transaction tx = null;
    public String hql = null;
    /* (non-Javadoc)
     * @see com.sthelens.pmf.dao.ErrorLogDao#getAllErrorLogs()
     */
    public List<ErrorLog> getAllErrorLogs() {
        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see com.sthelens.pmf.dao.ErrorLogDao#getErrorLog(java.lang.Integer)
     */
    public List<ErrorLog> getErrorLog(Integer id) {
    Criterion objectId = Restrictions.eq("ErrorLog.id", id);

       
        Criteria crit_a = session.createCriteria(
                ErrorLog.class, "ErrorLog").setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).add(objectId);
       
   
        //System.out.println("size "+crit_a.list().size());
   
        return crit_a.list();
    }

    /* (non-Javadoc)
     * @see com.sthelens.pmf.dao.ErrorLogDao#saveObject(com.sthelens.pmf.objects.errorLog.ErrorLog)
     */
    public Integer saveObject(ErrorLog errorLog) {
        Integer genID = (Integer)session.save( errorLog);
       
       
        return genID ;
    }

}

import com.project.objects.user;
import com.project.objects.errorLog.ErrorLog;

public interface ErrorLogService {

    public Integer createErrorLog(String action, Throwable exception, User off, String parameters);
   
   
    public ErrorLog getErrorLog(Integer id);
}

import java.util.List;

import com.project.dao.ErrorLogDao;
import com.project.dao.hibernate.ErrorLogDaoHibernate;
import com.project.objects.Officers;
import com.project.objects.errorLog.ErrorLog;
import com.project.service.ErrorLogService;

public class ErrorLogServiceImpl implements ErrorLogService{
/* (non-Javadoc)
     * @see com.sthelens.pmf.service.ErrorLogService#getErrorLog(java.lang.Integer)
     */
    public ErrorLog getErrorLog(Integer id) {
        List<ErrorLog> errLogs = this.errorLogDao.getErrorLog(id);
        if(errLogs.size() >0){
            return errLogs.get(0);
        }
        return null;
    }


/**
     *
     */
    public ErrorLogServiceImpl() {
        errorLogDao = new ErrorLogDaoHibernate();
    }


private ErrorLogDao errorLogDao;


    /* (non-Javadoc)
     * @see com.sthelens.pmf.service.ErrorLogService#createErrorLog(java.lang.String, java.lang.String, com.sthelens.pmf.objects.Officers, java.lang.String)
     */
    public Integer createErrorLog(String action, Throwable exception,
            User off, String parameters) {
        ErrorLog errorLog = new ErrorLog();
        errorLog.setAction(action);
        errorLog.fillMessage(exception);
        errorLog.setErrorBy(off);
        java.util.Date today =
            new java.util.Date();
        java.sql.Timestamp sqlToday =
       new java.sql.Timestamp(today.getTime());
        errorLog.setErrorTime(sqlToday);
       
        errorLog.setParameters(parameters);
       
       
        return this.errorLogDao.saveObject(errorLog);
    }

   
}


Usage
   
}catch (Exception e){
            ErrorLogService errorLogService = new ErrorLogServiceImpl();
       
           
            response.sendRedirect("./errorPage.do?id=" +
                    errorLogService.createErrorLog(this.getClass().getCanonicalName(),
                            e,
                            (Officers)request.getSession().getAttribute("LogIn"),
                            request.getQueryString()));
            return null;
    }
Views: 783 | Added by: The_Kat | Date: 2010-11-30 | Comments (0)

« 1 2 ... 5 6 7 8 9 ... 12 13 »
Login form
Adverts
Search
Calendar
«  May 2024  »
SuMoTuWeThFrSa
   1234
567891011
12131415161718
19202122232425
262728293031
Entries archive
Site friends
  • Create your own site
  • Spree4.com
  • My Blog
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    spree4
    Copyright MyCorp © 2024
    Website builderuCoz