Changeset f326ef1 in murachi


Ignore:
Timestamp:
Aug 17, 2015, 5:43:00 PM (9 years ago)
Author:
antonioaraujob <aaraujo@…>
Branches:
master
Children:
99d1e61
Parents:
efcd8d1
Message:

Corrección de error de fechas iguales en firmas múltiples en un contenedor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • murachi/src/main/java/ve/gob/cenditel/murachi/MurachiRESTWS.java

    refcd8d1 rf326ef1  
    335335         * @return archivo pasado como argumento del servidor
    336336         */
    337         /*
     337       
    338338        private Response downloadFileFromServer(String fileName) {   
    339339            String fileLocation = SERVER_UPLOAD_LOCATION_FOLDER + fileName;
     
    361361            return response;
    362362          }
    363         */
    364        
     363       
     364       
     365        /*
    365366        private Response downloadFileFromServer(String fileName) {   
    366367                logger.info("downloadFileFromServer{"+fileName+"}");
     
    380381            if (checkFileExists(SERVER_UPLOAD_LOCATION_FOLDER + fileName + "-serialized.bin")) {
    381382               
    382                 logger.debug("  descarga de contenedor BDOC");
     383                logger.debug("  descarga de contenedor BDOC: " + SERVER_UPLOAD_LOCATION_FOLDER + fileName + "-serialized.bin");
    383384               
    384385                try {                           
     
    388389                                // deserializar el contenedor
    389390                                c = deserialize(SERVER_UPLOAD_LOCATION_FOLDER + fileName + "-serialized.bin");
     391                                logger.debug("  deserializado contenedor: " + SERVER_UPLOAD_LOCATION_FOLDER + fileName + "-serialized.bin");
     392                               
     393                                logger.debug("numero de dataFile: "+ Integer.toString(c.getDataFiles().size()));
     394                                logger.debug("numero de firmas: "+ Integer.toString(c.getSignatures().size()));
     395                               
    390396                       
    391397                                // guardar el contenedor .bdoc
     
    431437            return response;
    432438          }
     439        */
    433440       
    434441       
     
    28562863        }
    28572864
    2858         // ------------> a seguir       
     2865               
    28592866       
    28602867        /**
     
    28682875        @Produces(MediaType.APPLICATION_JSON)
    28692876        public Response getSignatureNumber(@PathParam("containerId")  String containerId) {
    2870                 logger.info("/bdocs/archivos/"+containerId);
     2877                logger.info("/bdocs/firmas/"+containerId);
    28712878                                                               
    28722879                String fullPathBdocFile = SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized.bin";
     
    29182925                return response;               
    29192926        }
     2927       
     2928       
     2929        /**
     2930         * Elimina una firma de un contendor firmado
     2931         *
     2932         * @param containerId identificador del contenedor para eliminar la firma
     2933         * @param signatureId identificador de la firma a eliminar
     2934         *
     2935         * @return identificador del contenedor
     2936         */
     2937        @GET
     2938        @Path("/bdocs/firmas/papelera/{containerId}/{signatureId}")
     2939        @Produces(MediaType.APPLICATION_JSON)
     2940        public Response removeSignature(@PathParam("containerId")  String containerId, @PathParam("signatureId") int signatureId) {
     2941                logger.info("recurso /bdocs/firmas/papelera/"+containerId+"/"+Integer.toString(signatureId));
     2942               
     2943                logger.debug("dataFileId: " + Integer.toString(signatureId));
     2944               
     2945                String fullPathBdocFile = SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized.bin";
     2946                logger.debug(fullPathBdocFile);
     2947               
     2948               
     2949                JSONObject json = new JSONObject();
     2950                int signatureNumber = 0;
     2951               
     2952                Response response = null;
     2953                               
     2954                // Retrieve the file
     2955            File file = new File(fullPathBdocFile);
     2956            if (file.exists()) {
     2957                               
     2958                Security.addProvider(new BouncyCastleProvider());
     2959                                               
     2960                        Configuration configuration = new Configuration(Configuration.Mode.PROD);
     2961                        configuration.loadConfiguration(DIGIDOC4J_CONFIGURATION);
     2962                        configuration.setTslLocation(DIGIDOC4J_TSL_LOCATION);
     2963               
     2964                        Container container = null;
     2965                       
     2966                        try {
     2967                                container = deserialize(fullPathBdocFile);
     2968                                logger.debug("  contenedor " + fullPathBdocFile + " deserializado");
     2969                        } catch (ClassNotFoundException e) {
     2970
     2971                                response = Response.status(500).entity("{\"error\": \"no se pudo leer el contenido del contenedor\"}").type("text/plain").build();
     2972                                logger.error("no se pudo deserializar el contenedor para leer su contenido");
     2973                        }
     2974                        catch (IOException e) {
     2975                                response = Response.status(500).entity("{\"error\": \"no se pudo leer el contenido del contenedor\"}").type("text/plain").build();
     2976                                logger.error("no se pudo deserializar el contenedor para leer su contenido");
     2977                        }
     2978                               
     2979                        // contenedor deserializado, ahora verficar que este firmado
     2980                        signatureNumber = container.getSignatures().size();                                                     
     2981                        logger.debug("  signatureNumber: "+ Integer.toString(signatureNumber));
     2982                       
     2983                        if (signatureNumber < 1)
     2984                        {
     2985                                // el archivo esta firmado y no se puede eliminar el dataFile
     2986                                response = Response.status(200).entity("{\"error\": \"el contenedor no está firmado\"}").type("text/plain").build();
     2987                                logger.error("el contenedor no está firmado.");
     2988                        }
     2989                        else
     2990                        {                               
     2991                                if (signatureId >= signatureNumber)
     2992                                {
     2993                                        // el dataFileId no es valido
     2994                                        response = Response.status(200).entity("{\"error\": \"el identificador de la firma a eliminar no es valido\"}").type("text/plain").build();
     2995                                        logger.error("el identificador de la firma a eliminar no es valido.");
     2996                                }
     2997                                else
     2998                                {
     2999                                        // eliminar la firma
     3000                                        container.removeSignature(signatureId);
     3001                                        logger.debug("  eliminada signature: "+Integer.toString(signatureId));
     3002                               
     3003                                        // serializar el contenedor de nuevo
     3004                                        try {
     3005                                                serialize(container, SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized");
     3006                                                logger.debug("  serializado contenedor:" + fullPathBdocFile + " serializado.");
     3007                                       
     3008                                                json.put("mensaje", "firma eliminada correctamente");                           
     3009                                                response = Response.status(200).entity(json.toString()).build();
     3010                                       
     3011                                        } catch (IOException e) {
     3012                                                logger.error("error en la serializacion del contenedor: " + fullPathBdocFile);
     3013                                                response = Response.status(500).entity("{\"error\": \"no se serializar el contenedor\"}").type("text/plain").build();
     3014                                        }                                       
     3015                                }                               
     3016                        }                       
     3017                } else {
     3018                logger.error("El contenedor con id: "+containerId+ " no existe.");
     3019                json.put("error", "El contenedor con id: "+containerId+ " no existe.");
     3020                response = Response.status(404).entity(json.toString()).build();
     3021            }
     3022                return response;
     3023                       
     3024        }
     3025       
     3026        // ------------> a seguir
    29203027       
    29213028       
     
    30913198        public Response postsignBDOCContainer(PostsignParameters postsignPar) throws IOException, MurachiException {
    30923199               
    3093                 logger.info("recurso /bdocs/resenas");
     3200                logger.info("recurso /bdocs/firmas/post");
    30943201
    30953202                // cadena con la firma
     
    31003207                // obtener el id del archivo a firmar
    31013208                String containerId = postsignPar.getContainerId();
    3102                
    3103                 /*
    3104                 HttpSession session = req.getSession(false);
    3105                
    3106                 String fileId = (String) session.getAttribute("fileId");
    3107                 System.out.println("fileId: " + fileId);
    3108                 logger.debug("fileId: " + fileId);
    3109                 */
    3110                
     3209                               
    31113210                String signedBdoc = containerId + ".bdoc";
    31123211                logger.debug("  sigendBdoc: " + signedBdoc);
     
    31263225                        logger.debug("asignada firma al contenedor");
    31273226                       
    3128                        
     3227                        /*
    31293228                        //deserializedContainer.save(SERVER_UPLOAD_LOCATION_FOLDER + signedBdoc);
    31303229                        serialize(deserializedContainer, SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized");
    31313230                        logger.debug(" serializado el contenedor: " + SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized");
    3132                        
    3133                         //
    3134                         //File f = new File(serializedContainerId);
     3231                        */
     3232                       
     3233                       
     3234                        // prueba para evitar que las firmas tengan la misma hora de aplicacion
     3235
     3236                        // escribir el contendedor
     3237                        deserializedContainer.save(SERVER_UPLOAD_LOCATION_FOLDER + containerId + ".bdoc");
     3238                       
     3239                        // abrir el contenedor
     3240                        Configuration configuration = new Configuration(Configuration.Mode.PROD);                       
     3241                        configuration.loadConfiguration(DIGIDOC4J_CONFIGURATION);
     3242                        configuration.setTslLocation(DIGIDOC4J_TSL_LOCATION);                   
     3243                        Container c = Container.open(SERVER_UPLOAD_LOCATION_FOLDER + containerId + ".bdoc", configuration);
     3244                        logger.debug("  contenedor abierto: " + SERVER_UPLOAD_LOCATION_FOLDER + containerId + ".bdoc");                 
     3245                       
     3246                        // serializar el contenedor
     3247                        serialize(c, SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized");
     3248                        logger.debug("  serializado contenedor: " + SERVER_UPLOAD_LOCATION_FOLDER + containerId + "-serialized");
     3249                       
     3250                        // eliminar el contenedor guardado
     3251                        //File f = new File(SERVER_UPLOAD_LOCATION_FOLDER + containerId + ".bdoc");
    31353252                        //f.delete();
    31363253                       
     
    31563273                               
    31573274                JSONObject jsonFinalResult = new JSONObject();
    3158                 jsonFinalResult.put("signedFileId", containerId);
     3275                jsonFinalResult.put("signedFileId", containerId+".bdoc");
    31593276               
    31603277                logger.info(jsonFinalResult.toString());
Note: See TracChangeset for help on using the changeset viewer.