Update of 
/var/cvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms
In directory james.mmbase.org:/tmp/cvs-serv7654

Modified Files:
        HighFrequencyImagAction.java 
Log Message:
CMSC-1126 (format the action)


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms
See also: http://www.mmbase.org/jira/browse/CMSC-1126


Index: HighFrequencyImagAction.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/HighFrequencyImagAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- HighFrequencyImagAction.java        3 Dec 2008 10:21:51 -0000       1.2
+++ HighFrequencyImagAction.java        4 Dec 2008 03:21:05 -0000       1.3
@@ -30,69 +30,76 @@
 import com.finalist.cmsc.struts.PagerAction;
 import com.finalist.cmsc.util.ComparisonUtil;
 
+/**
+ * Select the often used images in all channels or in the current channel.
+ * 
+ * @author Eva & Marco
+ */
 public class HighFrequencyImagAction extends PagerAction {
 
    private static final String REPOSITORY_SEARCH_RESULTS_PER_PAGE = 
"repository.search.results.per.page";
    private static final String CHANNELID = "channelid";
-   private static final String RESULTCOUNT = "resultcount";
+   private static final String RESULTCOUNT = "resultCount";
    private static final String RESULTS = "results";
    private static final String SUCCESS = "success";
    private static final String CONTENTCHANNEL = "contentchannel";
    private static final String CREATIONREL = "creationrel";
-   private static final String DESTINATION = "destination";
    private static final String CURRENTCHANNEL = "current";
+   private static final String IMAGES = "images";
+   private static final String ALL = "all";
+   private static final String CREATION = "creation";
+   private static final String CONTENTELEMENT = "contentelement";
+   private static final String SOURCE = "source";
+   private static final String IMAGEREL = "imagerel";
+   private static final String NUMBER = "number";
+   private static final String IMAGENUMBER = "imageNumber";
+   private static final String COUNT = "count";
+   private static final String CON = "con";
 
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
HttpServletRequest request,
          HttpServletResponse response, Cloud cloud) throws Exception {
 
       HighFrequencyForm highFrequencyForm = (HighFrequencyForm) form;
-
-      
       Query query = cloud.createAggregatedQuery();
       Step step;
+      NodeManager imgManager = cloud.getNodeManager(IMAGES);
       //search in one contentchannel
-      NodeManager imgManager = cloud.getNodeManager("images");
-      String channelid=highFrequencyForm.getChannelid();
-      if(!StringUtil.isEmpty(channelid)&&!"all".equals(channelid)){
+      String channelid = highFrequencyForm.getChannelid();
+      if (!StringUtil.isEmpty(channelid) && !ALL.equals(channelid)) {
       //search in the current channel
-         if(CURRENTCHANNEL.equals(channelid)){
-            channelid = (String)request.getSession().getAttribute("creation");
+         if (CURRENTCHANNEL.equals(channelid)) {
+            channelid = (String) request.getSession().getAttribute(CREATION);
          }
          NodeManager channelManager = cloud.getNodeManager(CONTENTCHANNEL);
          query.addStep(channelManager);
-         RelationStep 
creationrelStep=query.addRelationStep(imgManager,CREATIONREL,"source");
-         step=creationrelStep.getNext();
+         RelationStep creationrelStep = query.addRelationStep(imgManager, 
CREATIONREL, SOURCE);
+         step = creationrelStep.getNext();
          Queries.addConstraints(query, channelManager.getName() + ".number=" + 
channelid);
-         request.setAttribute(CHANNELID, channelid);
-      }else{
+      } else {
          step = query.addStep(imgManager);
       }
-      NodeManager relManager = cloud.getNodeManager("contentelement");
-      RelationStep relStep = query.addRelationStep(relManager, "imagerel", 
"source");
+      NodeManager relManager = cloud.getNodeManager(CONTENTELEMENT);
+      RelationStep relStep = query.addRelationStep(relManager, IMAGEREL, 
SOURCE);
       Step contentStep = relStep.getNext();
-      query.addAggregatedField(step, imgManager.getField("number"), 
AggregatedField.AGGREGATION_TYPE_GROUP_BY);
+      query.addAggregatedField(step, imgManager.getField(NUMBER), 
AggregatedField.AGGREGATION_TYPE_GROUP_BY);
 
       BasicAggregatedField field = (BasicAggregatedField) 
query.addAggregatedField(contentStep, relManager
-            .getField("number"), AggregatedField.AGGREGATION_TYPE_COUNT);
-      field.setAlias("con");
-      
-      
-      
-      
+            .getField(NUMBER), AggregatedField.AGGREGATION_TYPE_COUNT);
+      field.setAlias(CON);
 
       NodeList middleResults = query.getList();
       List<Map<Object, Object>> results = new ArrayList<Map<Object, Object>>();
       for (int i = 0; i < middleResults.size(); i++) {
          Map<Object, Object> result = new HashMap<Object, Object>();
          Node n = middleResults.getNode(i);
-         result.put("imageNumber", n.getValue("number"));
-         result.put("count", n.getIntValue("con"));
+         result.put(IMAGENUMBER, n.getValue(NUMBER));
+         result.put(COUNT, n.getIntValue(CON));
          results.add(result);
 
       }
 
       ComparisonUtil comparator = new ComparisonUtil();
-      comparator.setFields_user(new String[] { "count" });
+      comparator.setFields_user(new String[] { COUNT });
       Collections.sort(results, comparator);
       Collections.reverse(results);
 
@@ -101,13 +108,12 @@
       NodeList imgResult = query1.getList();
 
       List<Node> newresult = new ArrayList<Node>();
-
       int x = 0;
       for (int i = 0; i < results.size(); i++) {
-         int mid = (Integer) results.get(i).get("imageNumber");
+         int mid = (Integer) results.get(i).get(IMAGENUMBER);
          for (int j = 0; j < imgResult.size(); j++) {
             Node img = imgResult.getNode(j);
-            if (mid == img.getIntValue("number")) {
+            if (mid == img.getIntValue(NUMBER)) {
                newresult.add(x++, img);
                imgResult.remove(img);
                break;
@@ -116,6 +122,7 @@
       }
 
       int resultCount = newresult.size();
+      
       // used for paging about maxnum
       int maxnum = 0;
       String resultsPerPage = 
PropertiesUtil.getProperty(REPOSITORY_SEARCH_RESULTS_PER_PAGE);
@@ -136,6 +143,7 @@
       } else {
          resultAfterPaging = newresult.subList(offset * maxnum, 
newresult.size());
       }
+      request.setAttribute(CHANNELID, channelid);
       request.setAttribute(RESULTCOUNT, resultCount);
       request.setAttribute(RESULTS, resultAfterPaging);
       return mapping.findForward(SUCCESS);
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to