Update of
/var/cvs/contributions/CMSContainer_Portlets/portlets-newsletter/src/java/com/finalist/newsletter/cao/impl
In directory james.mmbase.org:/tmp/cvs-serv20175/impl
Modified Files:
NewsLetterStatisticCAOImpl.java
Log Message:
CMSC-899,Check and improve all lists according to guideline,add Javadoc comment
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Portlets/portlets-newsletter/src/java/com/finalist/newsletter/cao/impl
See also: http://www.mmbase.org/jira/browse/CMSC-899
Index: NewsLetterStatisticCAOImpl.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Portlets/portlets-newsletter/src/java/com/finalist/newsletter/cao/impl/NewsLetterStatisticCAOImpl.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- NewsLetterStatisticCAOImpl.java 24 Jul 2008 11:45:43 -0000 1.16
+++ NewsLetterStatisticCAOImpl.java 23 Sep 2008 07:52:39 -0000 1.17
@@ -28,17 +28,16 @@
import com.finalist.newsletter.domain.StatisticResult;
import com.finalist.newsletter.domain.StatisticResult.HANDLE;
-
public class NewsLetterStatisticCAOImpl implements NewsLetterStatisticCAO {
private Cloud cloud;
- private static Logger log = Logging
.getLoggerInstance(NewsLetterStatisticCAOImpl.class.getName());
+ private static Logger log =
Logging.getLoggerInstance(NewsLetterStatisticCAOImpl.class.getName());
public void setCloud(Cloud cloud) {
this.cloud = cloud;
}
- public List<StatisticResult> getAllRecords() {
+ public List < StatisticResult > getAllRecords() {
NodeQuery query = cloud.createNodeQuery();
Step step =
query.addStep(cloud.getNodeManager("newsletterdailylog"));
@@ -48,7 +47,7 @@
return util.convertFromNodeList(list);
}
- public List<StatisticResult> getRecordsByNewsletter(int newsletter) {
+ public List < StatisticResult > getRecordsByNewsletter(int newsletter) {
NodeQuery query = cloud.createNodeQuery();
NodeManager manager =
cloud.getNodeManager("newsletterdailylog");
Step step1 = query.addStep(manager);
@@ -67,7 +66,7 @@
return util.convertFromNodeList(list);
}
- public List<StatisticResult> getAllRecordsByPeriod(Date start, Date
end) {
+ public List < StatisticResult > getAllRecordsByPeriod(Date start, Date end)
{
NodeQuery query = cloud.createNodeQuery();
NodeManager manager =
cloud.getNodeManager("newsletterdailylog");
Step step1 = query.addStep(manager);
@@ -78,7 +77,7 @@
query.addField(step1, manager.getField("removed"));
query.addField(step1, manager.getField("newsletter"));
StepField field = query.addField(step1,
manager.getField("logdate"));
- BasicFieldValueBetweenConstraint constraint = new
BasicFieldValueBetweenConstraint( field, start, end);
+ BasicFieldValueBetweenConstraint constraint = new
BasicFieldValueBetweenConstraint(field, start, end);
query.setConstraint(constraint);
query.setNodeStep(step1);
NodeList list = query.getList();
@@ -86,19 +85,20 @@
return util.convertFromNodeList(list);
}
- public List<StatisticResult> getLogs(){
+ /**
+ * @return List which sumLogs about StatisticResult
+ */
+ public List < StatisticResult > getLogs() {
NodeList nodelist = getNodelist();
synchronized (this) {
- List<StatisticResult> logsList = new
ArrayList<StatisticResult>();
-
- List<StatisticResult> resultList =
getLogsByNode(nodelist);
+ List < StatisticResult > logsList = new ArrayList < StatisticResult
>();
+ List < StatisticResult > resultList = getLogsByNode(nodelist);
if (null != resultList) {
// use newsletterId and userId as key to take
the logic
- Map<String, StatisticResult> sumedMap = new
HashMap<String, StatisticResult>();
+ Map < String , StatisticResult > sumedMap = new HashMap < String ,
StatisticResult >();
for (StatisticResult r : resultList) {
String uniteKey = r.getNewsletterId() +
"H" + r.getUserId();
- StatisticResult freq =
(StatisticResult) sumedMap
- .get(uniteKey);
+ StatisticResult freq = (StatisticResult) sumedMap.get(uniteKey);
if (freq == null) {
freq = r;
} else {
@@ -109,12 +109,10 @@
if (null != sumedMap) {
deleteOldLogsByNode(nodelist);
- for (Iterator iter =
sumedMap.keySet().iterator(); iter
- .hasNext();) {
+ for (Iterator iter = sumedMap.keySet().iterator();
iter.hasNext();) {
StatisticResult result = new
StatisticResult();
String element = (String)
iter.next();
- StatisticResult child =
(StatisticResult) sumedMap
- .get(element);
+ StatisticResult child = (StatisticResult)
sumedMap.get(element);
result = sumLogs(result, child);
String[] i = element.split("H");
result.setNewsletterId(Integer.parseInt(i[0]));
@@ -131,13 +129,13 @@
}
private StatisticResult sumLogs(StatisticResult freq, StatisticResult
r) {
- StatisticResult result=new StatisticResult();
- result.setBounches(freq.getBounches()+r.getBounches());
+ StatisticResult result = new StatisticResult();
+ result.setBounches(freq.getBounches() + r.getBounches());
result.setName(r.getName());
- result.setPost(freq.getPost()+r.getPost());
- result.setRemoved(freq.getRemoved()+r.getRemoved());
- result.setSubscribe(freq.getSubscribe()+r.getSubscribe());
- result.setUnsubscribe(freq.getUnsubscribe()+r.getUnsubscribe());
+ result.setPost(freq.getPost() + r.getPost());
+ result.setRemoved(freq.getRemoved() + r.getRemoved());
+ result.setSubscribe(freq.getSubscribe() + r.getSubscribe());
+ result.setUnsubscribe(freq.getUnsubscribe() + r.getUnsubscribe());
return result;
}
@@ -151,7 +149,7 @@
StepField field = query.addField(step,
manager.getField("logdate"));
StepField field1 = query.addField(step,
manager.getField("post"));
BasicFieldValueBetweenConstraint constraint = new
BasicFieldValueBetweenConstraint(field, startDate, endDate);
- BasicFieldValueConstraint constraint1=new
BasicFieldValueConstraint(field1, 0);
+ BasicFieldValueConstraint constraint1 = new
BasicFieldValueConstraint(field1, 0);
constraint1.setOperator(FieldCompareConstraint.GREATER);
BasicCompositeConstraint constraints = new
BasicCompositeConstraint(2);
constraints.addChild(constraint);
@@ -161,15 +159,13 @@
NodeList list = null;
try {
list = query.getList();
- }
- catch (NullPointerException e) {
+ } catch (NullPointerException e) {
log.debug(e.toString());
}
return list;
}
-
- private List<StatisticResult> getLogsByNode (NodeList list) {
+ private List < StatisticResult > getLogsByNode(NodeList list) {
StatisticUtil util = new StatisticUtil();
return util.convertFromNodeList(list);
}
@@ -188,8 +184,7 @@
}
- public List<StatisticResult> getRecordsByNewsletterAndPeriod(Date start,
- Date end, int newsletter) {
+ public List < StatisticResult > getRecordsByNewsletterAndPeriod(Date start,
Date end, int newsletter) {
NodeQuery query = cloud.createNodeQuery();
NodeManager manager =
cloud.getNodeManager("newsletterdailylog");
Step step1 = query.addStep(manager);
@@ -207,27 +202,26 @@
constraints.addChild(constraint2);
query.setConstraint(constraints);
query.setNodeStep(step1);
- List<Node> list = query.getList();
+ List < Node > list = query.getList();
StatisticUtil util = new StatisticUtil();
return util.convertFromNodeList((NodeList) list);
}
public void logPubliction(int userId, int newsletterId, HANDLE handle) {
- if (!mayLog(userId, newsletterId,handle)) {
+ if (!mayLog(userId, newsletterId, handle)) {
return;
}
Node logNode = null;
if (handle.equals(HANDLE.BOUNCE)) {
logNode = getLogNode(userId, newsletterId);
}
- if(logNode != null) {
- logNode.setIntValue("bounches", logNode.getIntValue("bounches")+1);
+ if (logNode != null) {
+ logNode.setIntValue("bounches", logNode.getIntValue("bounches") + 1);
logNode.setDateValue("logdate", new Date());
logNode.commit();
- }
- else {
+ } else {
NodeManager logManager = cloud.getNodeManager("newsletterdailylog");
- //Node newsletter = cloud.getNode(newsletterId);
+ // Node newsletter = cloud.getNode(newsletterId);
logNode = logManager.createNode();
logNode.setIntValue("newsletter", newsletterId);
logNode.setIntValue("post", 0);
@@ -239,17 +233,13 @@
logNode.setDateValue("logdate", new Date());
if (handle.equals(HANDLE.ACTIVE)) {
logNode.setIntValue("subscribe", 1);
- }
- else if (handle.equals(HANDLE.INACTIVE)) {
+ } else if (handle.equals(HANDLE.INACTIVE)) {
logNode.setIntValue("unsubscribe", 1);
- }
- else if (handle.equals(HANDLE.REMOVE)) {
+ } else if (handle.equals(HANDLE.REMOVE)) {
logNode.setIntValue("removed", 1);
- }
- else if (handle.equals(HANDLE.BOUNCE)) {
+ } else if (handle.equals(HANDLE.BOUNCE)) {
logNode.setIntValue("bounches", 1);
- }
- else if (handle.equals(HANDLE.POST)) {
+ } else if (handle.equals(HANDLE.POST)) {
logNode.setIntValue("post", 1);
}
logNode.commit();
@@ -257,9 +247,9 @@
}
- private boolean mayLog(int userId, int newsletterId,HANDLE handle) {
+ private boolean mayLog(int userId, int newsletterId, HANDLE handle) {
- if(!handle.equals(HANDLE.ACTIVE) && !handle.equals(HANDLE.INACTIVE)) {
+ if (!handle.equals(HANDLE.ACTIVE) && !handle.equals(HANDLE.INACTIVE)) {
return true;
}
@@ -272,27 +262,27 @@
query.setMaxNumber(3);
SearchUtil.addEqualConstraint(query,
logNodeManager.getField("newsletter"), new Integer(newsletterId));
- SearchUtil.addEqualConstraint(query,
logNodeManager.getField("userid"),new Integer(userId));
+ SearchUtil.addEqualConstraint(query, logNodeManager.getField("userid"),
new Integer(userId));
NodeList logs = query.getList();
if (logs.size() < 2) {
isLog = true;
- }
- else {
- int count = 0 ;
- for(int i = 0 ; i < logs.size() ; i++) {
+ } else {
+ int count = 0;
+ for (int i = 0; i < logs.size(); i++) {
Node log = logs.getNode(i);
- if(DateUtils.isSameDay(new Date(),
log.getDateValue("logdate")) && (log.getIntValue("subscribe") > 0 ||
log.getIntValue("unsubscribe") > 0)){
+ if (DateUtils.isSameDay(new Date(), log.getDateValue("logdate"))
+ && (log.getIntValue("subscribe") > 0 ||
log.getIntValue("unsubscribe") > 0)) {
count++;
}
}
- if(count == 3){
+ if (count == 3) {
isLog = false;
}
}
return isLog;
}
- public Node getLogNode(int userId, int newsletterId){
+ public Node getLogNode(int userId, int newsletterId) {
log.info("-------------------logPubliction -in
process...getLogNode....: ");
NodeManager logNodeManager = cloud.getNodeManager("newsletterdailylog");
Node logNode = null;
@@ -302,22 +292,27 @@
Queries.addSortOrders(query, "logdate", "DOWN");
query.setMaxNumber(1);
SearchUtil.addEqualConstraint(query,
logNodeManager.getField("newsletter"), new Integer(newsletterId));
- SearchUtil.addEqualConstraint(query,
logNodeManager.getField("userid"),new Integer(userId));
- FieldValueConstraint liConstraint =
query.createConstraint((query.getStepField(logNodeManager.getField("bounches"))),
- FieldCompareConstraint.GREATER, new Integer(0));
+ SearchUtil.addEqualConstraint(query, logNodeManager.getField("userid"),
new Integer(userId));
+ FieldValueConstraint liConstraint =
query.createConstraint((query.getStepField(logNodeManager
+ .getField("bounches"))), FieldCompareConstraint.GREATER, new
Integer(0));
SearchUtil.addConstraint(query, liConstraint);
NodeList logs = query.getList();
- if(logs != null && logs.size() >0){
- if(DateUtils.isSameDay(new Date(),
logs.getNode(0).getDateValue("logdate"))){
+ if (logs != null && logs.size() > 0) {
+ if (DateUtils.isSameDay(new Date(),
logs.getNode(0).getDateValue("logdate"))) {
logNode = logs.getNode(0);
}
}
return logNode;
}
- public int insertSumedLogs(List<StatisticResult> logsList) {
+
+ /**
+ * @param listRecorder which get from data
+ * @return how many SumedLogs insert
+ */
+ public int insertSumedLogs(List < StatisticResult > logsList) {
int i = 0;
NodeManager logManager =
cloud.getNodeManager("newsletterdailylog");
- Node logNode ;
+ Node logNode;
Date now = new Date();
Date start = DateUtils.addHours(now, -12);
for (StatisticResult r : logsList) {
@@ -336,8 +331,4 @@
return i;
}
-
-
-
-
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs