incubator-hise-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wi...@apache.org
Subject svn commit: r991109 - in /incubator/hise/trunk/hise-services/src/main/java/org/apache/hise: dao/HISEDao.java runtime/TaskHistoryListener.java
Date Tue, 31 Aug 2010 07:48:23 GMT
Author: witek
Date: Tue Aug 31 07:48:23 2010
New Revision: 991109

URL: http://svn.apache.org/viewvc?rev=991109&view=rev
Log:
HISE-53

Modified:
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/HISEDao.java
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskHistoryListener.java

Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/HISEDao.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/HISEDao.java?rev=991109&r1=991108&r2=991109&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/HISEDao.java (original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/HISEDao.java Tue
Aug 31 07:48:23 2010
@@ -19,9 +19,6 @@
 
 package org.apache.hise.dao;
 
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -36,7 +33,6 @@ import org.apache.commons.lang.Validate;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hise.dao.JpaQueryBuilder.JQBParam;
-import org.apache.hise.dao.Task.Status;
 import org.apache.hise.utils.StringToConverter;
 import org.apache.hise.utils.StringToConverterFabric;
 import org.springframework.orm.jpa.JpaCallback;
@@ -45,12 +41,21 @@ import org.springframework.orm.jpa.suppo
 
 /**
  * DAO.
- * 
  */
 public class HISEDao extends JpaDaoSupport {
 
     private static final Log log = LogFactory.getLog(HISEDao.class);
 
+    public List<TaskHistoryMessage> getHistoryMessages(final String language) {
+    	return (List<TaskHistoryMessage>) getJpaTemplate().executeFind(new JpaCallback()
{
+            public Object doInJpa(EntityManager em) throws PersistenceException {
+                return em.createQuery("select h from TaskHistoryMessage h where h.lang =
:lang")
+                .setParameter("lang", language)
+                .getResultList();
+            }
+        });
+    }
+    
     public OrgEntity getOrgEntity(final String name) {
         return (OrgEntity) getJpaTemplate().execute(new JpaCallback() {
             public Object doInJpa(EntityManager em) throws PersistenceException {
@@ -250,6 +255,7 @@ public class HISEDao extends JpaDaoSuppo
             getJpaTemplate().remove(o);
         }
     }
+
 	public<T> List find(final String query, final List parameters,  final Class<T>
what){
 		
 		JpaTemplate jpaTemp=getJpaTemplate();
@@ -262,12 +268,9 @@ public class HISEDao extends JpaDaoSuppo
 						//temp1=parameters.get(i);
 						q.setParameter(i+1, parameters.get(i));
 					}
-					List res=q.getResultList();					
-					
-        
-               	
-					return res;
-					
+
+					List res = q.getResultList();					
+					return res;					
 				}
 			});
 		

Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskHistoryListener.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskHistoryListener.java?rev=991109&r1=991108&r2=991109&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskHistoryListener.java
(original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskHistoryListener.java
Tue Aug 31 07:48:23 2010
@@ -18,7 +18,6 @@
  */
 package org.apache.hise.runtime;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -30,60 +29,69 @@ import org.apache.hise.dao.TaskHistoryMe
 
 /**
  * @author Paweł Byszewski
- *
+ * 
  */
 public class TaskHistoryListener {
 
-	public enum mode{
-		STATE_CHANGE,
-		ACTUALOWNER_CHANGE
+	public enum mode {
+		STATE_CHANGE, ACTUALOWNER_CHANGE
 	}
-	
+
 	private HISEEngine hiseEngine;
-	
-	public Comment stateChanged(org.apache.hise.dao.Task taskDto, org.apache.hise.dao.Task.Status
oldStatus,
-			org.apache.hise.dao.Task.Status newStatus, String initiator, String lang) {
-		Map<String,String> messages=getMessages(lang);
-		 if(initiator==null) throw new RuntimeException("Initiator name missing");
-		String content=null;
-        if(newStatus==Status.CREATED)
-        	content=messages.get(new String("CREATED"));
-        else{
-        	content=messages.get(new String("STATE_CHANGE"))+new String(oldStatus.toString())
-        			+" --> "+new String(newStatus.toString())+".";
-        }
-        Comment comment= new Comment(content, taskDto, initiator);
-        return comment;
-		
+
+	public Comment stateChanged(org.apache.hise.dao.Task taskDto, org.apache.hise.dao.Task.Status
oldStatus, org.apache.hise.dao.Task.Status newStatus,
+	        String initiator, String lang) {
+		Map<String, String> messages = getMessages(lang);
+		if (initiator == null) {
+			throw new RuntimeException("Initiator name missing");
+		}
+		String content = null;
+		if (newStatus == Status.CREATED) {
+			content = messages.get(new String("CREATED"));
+		} else {
+			content = messages.get(new String("STATE_CHANGE")) + new String(oldStatus.toString())
+ " --> " + new String(newStatus.toString()) + ".";
+		}
+		Comment comment = new Comment(content, taskDto, initiator);
+		return comment;
 	}
+
+	public Comment actualOwnerChanged(org.apache.hise.dao.Task taskDto, String oldActualOwner,
String newActualOwner, String initiator, String lang) {
+		Map<String, String> messages = getMessages(lang);
+		if (initiator == null) {
+			throw new RuntimeException("Initiator name missing");
+		}
+		if ((oldActualOwner == null || oldActualOwner.length() == 0) && (newActualOwner
== null || newActualOwner.length() == 0)) {
+			throw new RuntimeException("Names of old and new ActualOwner missing");
+		}
+
+		String content = null;
+		if (oldActualOwner == null || oldActualOwner.length() == 0) {
+			content = new String(messages.get(new String("NEW_ACTUALOWNER")) + newActualOwner + ".");
+		} else if (newActualOwner == null || newActualOwner.length() == 0) {
+			content = new String(messages.get(new String("DEL_ACTUALOWNER")) + ".");
+		} else {
+			content = new String(messages.get(new String("CHANGE_ACTUALOWNER")) + oldActualOwner +
" -->" + newActualOwner + ".");
+		}
+		Comment comment = new Comment(content, taskDto, initiator);
+		return comment;
+	}
+
+	private Map<String, String> getMessages(String lang) {
+		List<TaskHistoryMessage> messages = hiseEngine.getHiseDao().getHistoryMessages(lang);
+		Map<String, String> map = createMessageContentByTypeMap(messages);
+		return map;
+	}
+
+	private Map<String, String> createMessageContentByTypeMap(List<TaskHistoryMessage>
temp) {
+	    Map<String, String> messages = new HashMap<String, String>();
+		for (TaskHistoryMessage m : temp) {
+			messages.put(m.getType(), m.getContent()); // add(m.getContent());
+		}
+	    return messages;
+    }
+	
+	//IoC
 	
-	 public Comment actualOwnerChanged(org.apache.hise.dao.Task taskDto, String oldActualOwner,

-			 	String newActualOwner, String initiator, String lang){
-			Map<String,String> messages=getMessages(lang);
-		if(initiator==null) throw new RuntimeException("Initiator name missing");
-     	if((oldActualOwner==null || oldActualOwner.length()==0) &&
-     			(newActualOwner==null || newActualOwner.length()==0))
-     		throw new RuntimeException("Names of old and new ActualOwner missing");
-     	
-     	String content=null;
-	    if(oldActualOwner==null || oldActualOwner.length()==0)
-	        	content=new String(messages.get(new String("NEW_ACTUALOWNER"))+newActualOwner+".");
-	    else if(newActualOwner==null || newActualOwner.length()==0){
-	        	content=new String(messages.get(new String("DEL_ACTUALOWNER"))+".");
-	    }
-	    else{
-	        
-		        	content=new String(messages.get(new String("CHANGE_ACTUALOWNER"))+oldActualOwner+
-		        			" -->"+newActualOwner+".");
-	    }
-	    Comment comment= new Comment(content, taskDto, initiator);
-	    return comment;
-		
-		
-	}
-	 
-	 
-	 
 	public HISEEngine getHiseEngine() {
 		return hiseEngine;
 	}
@@ -91,22 +99,4 @@ public class TaskHistoryListener {
 	public void setHiseEngine(HISEEngine hiseEngine) {
 		this.hiseEngine = hiseEngine;
 	}
-
-	private Map<String,String> getMessages(String lang){
-			String query=new String("SELECT * FROM HISE_TASK_HISTORY_MESSAGE WHERE lang=?;");
-			List params=new ArrayList<String>();
-			params.add(lang);
-			List<TaskHistoryMessage> temp=hiseEngine.getHiseDao().find(query,params, TaskHistoryMessage.class);
-	        
-			
-			Map<String,String> messages=new HashMap<String, String>();
-			for (TaskHistoryMessage m : temp) {
-				messages.put(m.getType(), m.getContent());  //         add(m.getContent());
-			}
-			params.add(new String("PL"));
-			
-			
-	return messages;
-		
-		}
 }



Mime
View raw message