com.webbfontaine.valuewebb.bpm.DocumentHistory.java Source code

Java tutorial

Introduction

Here is the source code for com.webbfontaine.valuewebb.bpm.DocumentHistory.java

Source

package com.webbfontaine.valuewebb.bpm;

import com.webbfontaine.valuewebb.authentication.DaemonUser;
import com.webbfontaine.valuewebb.authentication.UserConstants;
import com.webbfontaine.valuewebb.authentication.UserInfoJosso;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

/**
 * Copyrights 2002-2010 Webb Fontaine
 * This software is the proprietary information of Webb Fontaine.
 * Its use is subject to License terms.
 * User: nigiyan
 * Date: Nov 2, 2010
 */

public abstract class DocumentHistory {

    private List<Object[]> history;

    private Object id;

    public abstract String getNativeQuery();

    public abstract EntityManager getEntityManager();

    public void loadHises() {
        if (id == null) {
            return;
        }
        Query query = getEntityManager().createNativeQuery(getNativeQuery());
        query.setParameter("id", id);
        history = (List<Object[]>) query.getResultList();

        loadUserDetails();
    }

    public List<Object[]> getHistory() {
        if (history == null) {
            loadHises();
        }
        return history;
    }

    private void loadUserDetails() {
        UserInfoJosso userInfoJosso = new UserInfoJosso();
        userInfoJosso.setUseCache(true);

        if (history != null) {
            for (Object[] details : history) {

                String userName = (String) details[5];

                if (!userName.equals(DaemonUser.DAEMON_USER_ID)) {
                    userInfoJosso.initRemoteUserInfo(userName);

                    String firstName = StringUtils.trimToEmpty(userInfoJosso.getProperty(UserConstants.GIVEN_NAME));
                    String lastName = StringUtils.trimToEmpty(userInfoJosso.getProperty(UserConstants.SURNAME));
                    String firstAndLastName = (firstName + lastName).length() == 0 ? ""
                            : " (" + firstName + ' ' + lastName + ')';

                    details[5] = details[5].toString() + firstAndLastName;
                }
            }
        }
    }

    public void action(Object id) {
        this.id = id;
    }

    public Object getId() {
        return id;
    }

    public void setId(Object id) {
        this.id = id;
    }

}