fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [6832] Many changes to exception handling


From: Petur Thorsteinsson
Subject: [Fmsystem-commits] [6832] Many changes to exception handling
Date: Mon, 24 Jan 2011 09:47:46 +0000

Revision: 6832
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6832
Author:   peturbjorn
Date:     2011-01-24 09:47:46 +0000 (Mon, 24 Jan 2011)
Log Message:
-----------
Many changes to exception handling

Modified Paths:
--------------
    thirdparty/BIM_converter/trunk/src/no/ifc/rest/UploadIfc.java

Modified: thirdparty/BIM_converter/trunk/src/no/ifc/rest/UploadIfc.java
===================================================================
--- thirdparty/BIM_converter/trunk/src/no/ifc/rest/UploadIfc.java       
2011-01-24 09:47:14 UTC (rev 6831)
+++ thirdparty/BIM_converter/trunk/src/no/ifc/rest/UploadIfc.java       
2011-01-24 09:47:46 UTC (rev 6832)
@@ -24,6 +24,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import no.bimfm.ifc.InvalidIfcFileException;
 import no.bimfm.ifc.RepositoriesImpl;
 import no.bimfm.ifc.RepositoryExceptionUc;
 import no.bimfm.ifc.v2x3.IfcModelImpl;
@@ -34,37 +35,27 @@
 
 @Path("/uploadIfc")
 public class UploadIfc {
+       private String repositoryName = "temporaryRepository";
        private Logger logger = 
LoggerFactory.getLogger("no.ifc.rest.UploadIfc");
        @GET
        @Produces(MediaType.TEXT_HTML)
        public String sayHtmlHello() {
-               String test = "noData3";
-               return test;
+       
+               String returnData = "You have accept type set to text/html, use 
POST to upload data";
+               return returnData;
        }
        
        @POST
        @Consumes("multipart/form-data")
-       @Produces(MediaType.TEXT_HTML)
-       public String uploadFile(@FormDataParam("file") File file, 
@FormDataParam("file") FormDataContentDisposition fcdsFile,  
@FormDataParam("file") InputStream attachmentFile,@FormDataParam("repoName") 
String repoName) {
+       @Produces(MediaType.APPLICATION_XML)
+       public String uploadFile(@FormDataParam("file") File file, 
@FormDataParam("file") FormDataContentDisposition fcdsFile,  
@FormDataParam("file") InputStream attachmentFile) {
                logger.debug("Upload initiated");
                //String fileLocation = "/files/" + fcdsFile.getFileName();
-               String fileLocation = fcdsFile.getFileName();
-               /*try {
-                       //System.out.println(attachmentFile.available());
-               } catch (IOException e1) {
-                       // TODO Auto-generated catch block
-                       e1.printStackTrace();
-               }*/
                String testIfcFileName = "myfile.ifc";
-               
                File destFile = new File(testIfcFileName);
-               
-               // your code here to copy file to destFile
-               
                InputStream in;
                OutputStream out;
                try {
-                       in = new FileInputStream(file);
                        in = attachmentFile;
                        out = new FileOutputStream(destFile);
                        byte[] buf = new byte[1024];
@@ -72,7 +63,6 @@
                        while ((len = in.read(buf)) > 0){
                                out.write(buf, 0, len);
                        }
-                       //file.close();
                        in.close();
                        out.close();
                        logger.info("Upload success!");
@@ -94,42 +84,33 @@
                logger.info("Path to save the file in is {}", path);
                
                RepositoriesImpl repo = new RepositoriesImpl();
-               repo.deleteAllRepositories();
+               //repo.deleteAllRepositories();
                System.out.println(path + "\\" + testIfcFileName);
                try {
-                       if(repo.addRepository(repoName, path + File.separator + 
testIfcFileName)){
+                       if(repo.addRepository(this.repositoryName, path + 
File.separator + testIfcFileName)){
                                WholeModelOutput wholeModel= new 
WholeModelOutput();
-                               IfcModelImpl model  = new 
IfcModelImpl(repoName);
+                               IfcModelImpl model  = new 
IfcModelImpl(this.repositoryName);
                                wholeModel.load(model);
-                               return extractModelXml(wholeModel);
+                               String result = extractModelXml(wholeModel);
+                               repo.deleteRepository(this.repositoryName);
+                               return result;
                        } else {
                                // should not get in here
-                               return "Error importing!";
+                               return "<?xml version=\"1.0\" 
encoding=\"UTF-8\" 
standalone=\"yes\"?><error><type>repository</type><message>Could not import 
repository</message></error>";
                        }
-                               
+                       
+               } catch (InvalidIfcFileException e) {
+                       logger.error("File was invalid");
+                       e.printStackTrace();
+                       return "<?xml version=\"1.0\" encoding=\"UTF-8\" 
standalone=\"yes\"?><error><type>invalidFile</type><message>Invalid 
file</message></error>";
                } catch (RepositoryExceptionUc e) {
-                       return e.getMessage();
+                       logger.error("Error importing");
+                       e.printStackTrace();
+                       return "<?xml version=\"1.0\" encoding=\"UTF-8\" 
standalone=\"yes\"?><error><type>general</type><message>"+e.getMessage()+"</message></error>";
                } finally {
-                       repo.deleteRepository(repoName);
+                       
                        destFile.delete();
                }
-               
-               /*
-               boolean repoCheck = false;
-               try {
-                       repoCheck = repo.checkIfRepoExists(repoName);
-               } catch (SdaiException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
-               if(repoCheck) {
-                       return "repo: "+ repoName + " exists!";
-               } else {
-                       return "repo: "+ repoName + " does not exist!";
-               }
-               
-               */
-               
        }
 
        private String extractModelXml(WholeModelOutput wholeModel) {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]