]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
First version of the Compare the Studies results method.
authormka <mka@opencascade.com>
Wed, 6 Mar 2013 14:04:54 +0000 (14:04 +0000)
committermka <mka@opencascade.com>
Wed, 6 Mar 2013 14:04:54 +0000 (14:04 +0000)
Workspace/Siman-Common/lib/iText-2.1.5.jar [new file with mode: 0644]
Workspace/Siman-Common/lib/jcommon-1.0.17.jar [new file with mode: 0644]
Workspace/Siman-Common/lib/jfreechart-1.0.14.jar [new file with mode: 0644]
Workspace/Siman-Common/src/conf/log-messages.properties
Workspace/Siman-Common/src/conf/log-messages_en.properties
Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java
Workspace/Siman-Common/src/org/splat/exception/IncompatibleDataException.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/StudyService.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java

diff --git a/Workspace/Siman-Common/lib/iText-2.1.5.jar b/Workspace/Siman-Common/lib/iText-2.1.5.jar
new file mode 100644 (file)
index 0000000..f28be38
Binary files /dev/null and b/Workspace/Siman-Common/lib/iText-2.1.5.jar differ
diff --git a/Workspace/Siman-Common/lib/jcommon-1.0.17.jar b/Workspace/Siman-Common/lib/jcommon-1.0.17.jar
new file mode 100644 (file)
index 0000000..f1bd165
Binary files /dev/null and b/Workspace/Siman-Common/lib/jcommon-1.0.17.jar differ
diff --git a/Workspace/Siman-Common/lib/jfreechart-1.0.14.jar b/Workspace/Siman-Common/lib/jfreechart-1.0.14.jar
new file mode 100644 (file)
index 0000000..0e4d020
Binary files /dev/null and b/Workspace/Siman-Common/lib/jfreechart-1.0.14.jar differ
index f947e086840ea67bcd321e78cb53dd1f49462ed6..5ee7cdbc88c4b90163f1ef7e9381cbc26226c8ce 100644 (file)
@@ -19,3 +19,4 @@ DCT-000001=Document type "{0}" already exists
 DCT-000002=Can not delete the document "{0}" because it is used by other documents.
 DCT-000003=Can not save a document in {0} state. Check the validation cycle.
 PRM-000001=Parameter {0} is invalid with value: {1}
+IDT-000001=Incompatible data: X-units or Y-units are not the same for all comparable studies.
\ No newline at end of file
index f1b20c6f913739ea1e5bd53d1ba8c1807d700e5b..5ee7cdbc88c4b90163f1ef7e9381cbc26226c8ce 100644 (file)
@@ -18,4 +18,5 @@ SCT-000001=Simulation context type "{0}" already exists
 DCT-000001=Document type "{0}" already exists
 DCT-000002=Can not delete the document "{0}" because it is used by other documents.
 DCT-000003=Can not save a document in {0} state. Check the validation cycle.
-PRM-000001=Parameter {0} is invalid with value: {1}
\ No newline at end of file
+PRM-000001=Parameter {0} is invalid with value: {1}
+IDT-000001=Incompatible data: X-units or Y-units are not the same for all comparable studies.
\ No newline at end of file
index eaea30f00eb18a27eed06f51bad61669debc2656..1b887474915dc56a4ffa917b4c11c5ac912eeadf 100644 (file)
@@ -93,10 +93,14 @@ public enum MessageKeyEnum {
         * DCT-000003=Can not save a document in {0} state. Check the validation cycle.
         */
        DCT_000003("DCT-000003"),
-               /**
+       /**
         * Parameter {0} is invalid with value: {1}.
         */
-       PRM_000001("PRM-000001");
+       PRM_000001("PRM-000001"),
+       /**
+        * Incompatible data: X-units or Y-units are not the same for all comparable studies.
+        */
+       IDT_000001("IDT-000001");
        /**
        * Value.
        */
diff --git a/Workspace/Siman-Common/src/org/splat/exception/IncompatibleDataException.java b/Workspace/Siman-Common/src/org/splat/exception/IncompatibleDataException.java
new file mode 100644 (file)
index 0000000..59a41c5
--- /dev/null
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   06.03.2013
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
+ *****************************************************************************/
+
+package org.splat.exception; 
+
+/**
+ * Exception thrown when data is incompatible for "Compare the studies" functionality.
+ * @author Maria KRUCHININA
+ *
+ */
+public class IncompatibleDataException extends BusinessException {
+
+       /**
+        * Version id for serialization.
+        */
+       private static final long serialVersionUID = -4596111071538834057L;
+       
+       /**
+        * Create a IncompatibleDataException.
+        * 
+        * @param message
+        *            the error message.
+        */
+       public IncompatibleDataException(final String message) {
+               super(message);
+       }
+}
index aea1958fcd95c574d033a5e9ac2659a0780375a5..9726ddb83f055c39b38cc231eac14851c017124f 100644 (file)
@@ -19,6 +19,7 @@ import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.Study.Properties;
 import org.splat.dal.bo.som.ValidationCycle;
+import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
@@ -308,9 +309,12 @@ public interface StudyService {
        /**
         * Compare the studies and generate the file that contains the result chart.
         * @param docsList the list of dtos each contains information: 
-        * StudyTitle, ScenarioTitle, PathToFile in vault. 
+        *        StudyTitle, ScenarioTitle, PathToFile in vault. 
+        * @param userName the name of the user who compare the results.       
+        * @throws IncompatibleDataException
+        *         if data is incompatible for "Compare the studies" functionality.
         * 
         * @return path to result file in the vault.
         */
-       String compare (List<DocToCompareDTO> docsList);
+       String compare (List<DocToCompareDTO> docsList, final String userName) throws IncompatibleDataException;
 }
index 7cc8aced510711d68a2aa78371fe7c54f353a50d..211f2d9683e827ffeff00b9f37769d868db95bd9 100644 (file)
@@ -9,6 +9,10 @@
 
 package org.splat.service;
 
+import java.awt.Graphics2D;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
@@ -18,9 +22,16 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Scanner;
 import java.util.Set;
 
 import org.hibernate.criterion.Restrictions;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+import org.splat.common.properties.MessageKeyEnum;
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ActorRelation;
@@ -47,6 +58,7 @@ import org.splat.dal.dao.som.PublicationDAO;
 import org.splat.dal.dao.som.ScenarioDAO;
 import org.splat.dal.dao.som.StudyDAO;
 import org.splat.dal.dao.som.ValidationCycleDAO;
+import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
@@ -60,6 +72,14 @@ import org.splat.service.technical.RepositoryService;
 import org.splat.som.Revision;
 import org.springframework.transaction.annotation.Transactional;
 
+import com.lowagie.text.Document;
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.Rectangle;
+import com.lowagie.text.pdf.DefaultFontMapper;
+import com.lowagie.text.pdf.PdfContentByte;
+import com.lowagie.text.pdf.PdfTemplate;
+import com.lowagie.text.pdf.PdfWriter;
+
 
 /**
  * This class defines all methods for creation, modification the study.
@@ -1129,9 +1149,119 @@ public class StudyServiceImpl implements StudyService {
                return study.removeAttribute(study.getAttribute(DescriptionAttribute.class));
        }
        
+       /**
+        * 
+        * {@inheritDoc}
+        * @see org.splat.service.StudyService#compare(java.util.List)
+        */
        @Override
-       public String compare (final List<DocToCompareDTO> docsList) {
-               return "Result file path";
+       public String compare (final List<DocToCompareDTO> docsList, final String userName) throws IncompatibleDataException{
+               
+               String axis1Name = "";
+               String axis2Name = "";
+               String resultPath = "";
+               
+               XYSeriesCollection dataset = new XYSeriesCollection();
+               
+               Iterator<DocToCompareDTO> docListIter = docsList.iterator();
+               
+               for (; docListIter.hasNext();) {
+                       
+                       DocToCompareDTO docDTO = docListIter.next();
+                       String pathToFile = docDTO.getPathToFile();
+                       File compDocFile = new File(pathToFile);
+                       
+                       resultPath = pathToFile.substring(0, pathToFile.indexOf("vault")) + "downloads" + File.separator + userName + File.separator + "ComparisonResult.pdf";
+                       
+                       XYSeries series = new XYSeries("Study: " + docDTO.getStudyTitle() + " Scenario: " + docDTO.getScenarioTitle());
+                       
+                       //read the file and get points information.
+                       try {
+                               Scanner input = new Scanner(compDocFile);
+                               
+                               //get the name of the axis.
+                               if (input.hasNext()) {
+                                       String[] tokens = input.nextLine().split(",");
+                                       if ("".equals(axis1Name)) {
+                                               axis1Name = tokens[0];
+                                       } else if (!axis1Name.equals(tokens[0])) {
+                                               LOG.debug("Axis must be the same for all documents");
+                                               throw new IncompatibleDataException(MessageKeyEnum.IDT_000001.toString());
+                                       }
+                                       
+                                       if ("".equals(axis2Name)) {
+                                               axis2Name = tokens[1];
+                                       } else if (!axis2Name.equals(tokens[1])) {
+                                               LOG.debug("Axis must be the same for all documents");
+                                               throw new IncompatibleDataException(MessageKeyEnum.IDT_000001.toString());
+                                       }
+                               }
+                               
+                               //Get the XY points series.
+                               while(input.hasNext()) {
+                                       
+                                       String currentString = input.nextLine();
+                                       
+                                       if ("".equals(currentString)) {
+                                               continue;
+                                       }
+                                       else {
+                                               String[] tokens = currentString.split(" ");
+                                               series.add(Double.valueOf(tokens[0]), Double.valueOf(tokens[1]));
+                                       }                   
+                                 
+                               } //while
+                               
+                               dataset.addSeries(series);
+                               
+                       } catch (FileNotFoundException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                               return "ERROR";
+                       }
+               } //for
+               
+               JFreeChart chart = ChartFactory.createXYLineChart(
+                               "Comparision of Studies Results", // Title
+                               axis1Name, // x-axis Label
+                               axis2Name, // y-axis Label
+                               dataset, // Dataset
+                               PlotOrientation.VERTICAL, // Plot Orientation
+                               true, // Show Legend
+                               true, // Use tooltips
+                               false // Configure chart to generate URLs?
+                               );
+               
+               //export to PDF - file.                 
+               int x = 500;
+               int y = 300;
+               Rectangle pagesize = new Rectangle(x, y);
+               Document document = new Document(pagesize, 50, 50, 50, 50);
+        PdfWriter writer;
+               try {
+                       File resFile = new File(resultPath);
+                       File resFolder = new File(resultPath.substring(0, resultPath.lastIndexOf(File.separator)));
+                       resFolder.mkdirs();
+                       writer = PdfWriter.getInstance(document, new FileOutputStream(resFile));
+               
+               document.open();
+               PdfContentByte cb = writer.getDirectContent();
+               PdfTemplate tp = cb.createTemplate(x, y);
+               Graphics2D g2 = tp.createGraphics(x, y, new DefaultFontMapper());
+               chart.draw(g2, new java.awt.Rectangle(x,y));
+               g2.dispose();
+               cb.addTemplate(tp, 0, 0);
+               document.close(); 
+        
+               } catch (FileNotFoundException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (DocumentException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               
+               return resultPath;
        }
 
        /**