@POST
  @Path("/documents")
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON})
  public Response createUploadFile(
      @HeaderParam("Content-Length") final Long fileSize,
      @FormDataParam("file") final InputStream inputStream,
      @FormDataParam("file") final FormDataContentDisposition fileDetails,
      @FormDataParam("file") final FormDataBodyPart bodyPart,
      @FormDataParam("status") final String name,
      @FormDataParam("description") final String description) {

    FileUtils.validateFileSizeWithinPermissibleRange(
        fileSize, name, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB);
    inputStreamObject = inputStream;
    DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
    final Date date = DateUtils.getDateOfTenant();
    final DateTimeFormatter dtf = DateTimeFormat.forPattern("dd MMMM yyyy");
    final LocalDate localdate = dtf.parseLocalDate(dateFormat.format(date));
    final String fileUploadLocation = FileUtils.generateXlsFileDirectory();
    final String fileName = fileDetails.getFileName();
    if (!new File(fileUploadLocation).isDirectory()) {
      new File(fileUploadLocation).mkdirs();
    }
    final DataUploadCommand uploadStatusCommand =
        new DataUploadCommand(
            name,
            null,
            localdate,
            "",
            null,
            null,
            null,
            description,
            fileName,
            inputStream,
            fileUploadLocation);
    CommandProcessingResult id = this.dataUploadWritePlatformService.addItem(uploadStatusCommand);
    return Response.ok().entity(id.toString()).build();
    // return null;
  }
Пример #2
0
  @POST
  @Path("/documents")
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON})
  public String createUploadFile(
      @HeaderParam("Content-Length") Long fileSize,
      @FormDataParam("file") InputStream inputStream,
      @FormDataParam("file") FormDataContentDisposition fileDetails,
      @FormDataParam("file") FormDataBodyPart bodyPart,
      @FormDataParam("name") String name,
      @FormDataParam("description") String description) {

    FileUtils.validateFileSizeWithinPermissibleRange(
        fileSize, name, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB);

    int i;

    /*DocumentCommand documentCommand = new DocumentCommand(null, null, null, null, name, fileDetails.getFileName(), fileSize,
    bodyPart.getMediaType().toString(), description, null);*/
    try {
      String fileUploadLocation = FileUtils.generateXlsFileDirectory();
      String fileName = fileDetails.getFileName();
      if (!new File(fileUploadLocation).isDirectory()) {
        new File(fileUploadLocation).mkdirs();
      }

      String fileLocation = FileUtils.saveToFileSystem(inputStream, fileUploadLocation, fileName);

      InputStream excelFileToRead = new FileInputStream(fileLocation);

      XSSFWorkbook wb = new XSSFWorkbook(excelFileToRead);

      XSSFSheet sheet = wb.getSheetAt(0);
      XSSFRow row;
      XSSFCell cell;
      String serialno = "0";
      int countno = Integer.parseInt(serialno);
      if (countno == 0) {
        countno = countno + 2;
      } else if (countno == 1) {
        countno = countno + 1;
      }
      System.out.println("Excel Row No is: " + countno);
      Iterator rows = sheet.rowIterator();
      Vector<XSSFCell> v = new Vector<XSSFCell>();
      if (countno > 0) {
        countno = countno - 1;
      }
      while (rows.hasNext()) {

        row = (XSSFRow) rows.next();
        i = row.getRowNum();
        if (i > 0) {
          if (i >= countno) {
            Iterator cells = row.cellIterator();
            while (cells.hasNext()) {

              cell = (XSSFCell) cells.next();

              if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
                // System.out.print(cell.getStringCellValue() +
                // " ");
                v.add(cell);
              } else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
                // System.out.print(cell.getNumericCellValue() +
                // " ");
                v.add(cell);
              } else {
                v.add(cell);
              }
            }
            // ItemDetailsCommand itemdetails=new
            // ItemDetailsCommand(Integer.parseInt(v.elementAt(0).toString()),v.elementAt(1).toString(),Integer.parseInt(v.elementAt(2).toString()),v.elementAt(3).toString(),v.elementAt(4).toString(),v.elementAt(5).toString(),Integer.parseInt(v.elementAt(6).toString()),Integer.parseInt(v.elementAt(7).toString()),Integer.parseInt(v.elementAt(8).toString()),v.elementAt(9).toString(),null);
            List<ItemDetailsCommand> ItemDetailsCommandList = new ArrayList<ItemDetailsCommand>();
            /*for(i=0;i<10;i++)
            {*/
            /* Iterator iterator = v.iterator();
             while(iterator.hasNext())
             {

            	System.out.println(v.elementAt(0).toString());
            	System.out.println( v.elementAt(1).toString());
            	System.out.println( v.elementAt(2).toString());
            	System.out.println( v.elementAt(3).toString());
            	System.out.println( v.elementAt(4).toString());
            	System.out.println( v.elementAt(5).toString());
            	System.out.println( v.elementAt(6).toString());
            	System.out.println( v.elementAt(7).toString());
            	System.out.println( v.elementAt(8).toString());
            	System.out.println( v.elementAt(9).toString());



            	// itemDetails = ItemDetails.create(command.getItemMasterId(), command.getSerialNumber(), command.getGrnId(),command.getProvisioningSerialNumber(), command.getQuality(),command.getStatus(), command.getOfficeId(), command.getClientId(), command.getWarranty(), command.getRemark());
            	//ItemDetailsCommand itemdetails=new ItemDetailsCommand(Long.parseLong(v.elementAt(0).toString()), v.elementAt(1).toString(), Long.parseLong(v.elementAt(2).toString()), v.elementAt(3).toString(), v.elementAt(4).toString(), v.elementAt(5).toString(), Long.parseLong(v.elementAt(6).toString()), Long.parseLong(v.elementAt(7).toString()), Long.parseLong(v.elementAt(8).toString()), v.elementAt(9).toString());
            	//ItemDetailsCommand itemdetails=new ItemDetailsCommand(Long.parseLong(v.elementAt(0).toString()), v.elementAt(1).toString(), Long.parseLong(v.elementAt(2).toString()), v.elementAt(3).toString(), v.elementAt(4).toString(), v.elementAt(5).toString(), Long.parseLong(v.elementAt(6).toString()), Long.parseLong(v.elementAt(7).toString()), Long.parseLong(v.elementAt(8).toString()), v.elementAt(9).toString());
            	//CommandProcessingResult id = this.itemDetailsWritePlatformService.addItem(itemdetails);
            	//ItemDetailsCommandList.add(itemdetails);

            	ItemDetailsCommand itemDetailsCommand=new ItemDetailsCommand();
            	new Double(v.elementAt(0).toString()).longValue();

            	itemDetailsCommand.setItemMasterId(new Double(v.elementAt(0).toString()).longValue());

            	itemDetailsCommand.setSerialNumber(v.elementAt(1).toString());
            	itemDetailsCommand.setGrnId(new Double(v.elementAt(2).toString()).longValue());
            	itemDetailsCommand.setProvisioningSerialNumber( v.elementAt(3).toString());
            	itemDetailsCommand.setQuality( v.elementAt(4).toString());
            	itemDetailsCommand.setRemark(v.elementAt(9).toString());
            	itemDetailsCommand.setStatus(v.elementAt(5).toString());
            	itemDetailsCommand.setOfficeId(new Double(v.elementAt(6).toString()).longValue());
            	itemDetailsCommand.setClientId(new Double(v.elementAt(7).toString()).longValue());
            	itemDetailsCommand.setWarranty(new Double(v.elementAt(8).toString()).longValue());
            	ItemDetailsCommandList.add(itemDetailsCommand);

            	CommandProcessingResult id = this.itemDetailsWritePlatformService.addItem(itemDetailsCommand);

            }
            */

          }
        }
      }
      Iterator iterator = v.iterator();
      while (iterator.hasNext()) {

        System.out.println(v.elementAt(0).toString());
        System.out.println(v.elementAt(1).toString());
        System.out.println(v.elementAt(2).toString());
        System.out.println(v.elementAt(3).toString());
        System.out.println(v.elementAt(4).toString());
        System.out.println(v.elementAt(5).toString());
        System.out.println(v.elementAt(6).toString());
        System.out.println(v.elementAt(7).toString());
        System.out.println(v.elementAt(8).toString());
        System.out.println(v.elementAt(9).toString());

        // itemDetails = ItemDetails.create(command.getItemMasterId(), command.getSerialNumber(),
        // command.getGrnId(),command.getProvisioningSerialNumber(),
        // command.getQuality(),command.getStatus(), command.getOfficeId(), command.getClientId(),
        // command.getWarranty(), command.getRemark());
        // ItemDetailsCommand itemdetails=new
        // ItemDetailsCommand(Long.parseLong(v.elementAt(0).toString()), v.elementAt(1).toString(),
        // Long.parseLong(v.elementAt(2).toString()), v.elementAt(3).toString(),
        // v.elementAt(4).toString(), v.elementAt(5).toString(),
        // Long.parseLong(v.elementAt(6).toString()), Long.parseLong(v.elementAt(7).toString()),
        // Long.parseLong(v.elementAt(8).toString()), v.elementAt(9).toString());
        // ItemDetailsCommand itemdetails=new
        // ItemDetailsCommand(Long.parseLong(v.elementAt(0).toString()), v.elementAt(1).toString(),
        // Long.parseLong(v.elementAt(2).toString()), v.elementAt(3).toString(),
        // v.elementAt(4).toString(), v.elementAt(5).toString(),
        // Long.parseLong(v.elementAt(6).toString()), Long.parseLong(v.elementAt(7).toString()),
        // Long.parseLong(v.elementAt(8).toString()), v.elementAt(9).toString());
        // CommandProcessingResult id = this.itemDetailsWritePlatformService.addItem(itemdetails);
        // ItemDetailsCommandList.add(itemdetails);

        ItemDetailsCommand itemDetailsCommand = new ItemDetailsCommand();
        new Double(v.elementAt(0).toString()).longValue();

        itemDetailsCommand.setItemMasterId(new Double(v.elementAt(0).toString()).longValue());

        itemDetailsCommand.setSerialNumber(v.elementAt(1).toString());
        itemDetailsCommand.setGrnId(new Double(v.elementAt(2).toString()).longValue());
        itemDetailsCommand.setProvisioningSerialNumber(v.elementAt(3).toString());
        itemDetailsCommand.setQuality(v.elementAt(4).toString());
        itemDetailsCommand.setRemark(v.elementAt(9).toString());
        itemDetailsCommand.setStatus(v.elementAt(5).toString());
        itemDetailsCommand.setOfficeId(new Double(v.elementAt(6).toString()).longValue());
        itemDetailsCommand.setClientId(new Double(v.elementAt(7).toString()).longValue());
        itemDetailsCommand.setWarranty(new Double(v.elementAt(8).toString()).longValue());
        // ItemDetailsCommandList.add(itemDetailsCommand);

        CommandProcessingResult id =
            this.itemDetailsWritePlatformService.addItem(itemDetailsCommand);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    /**
     * TODO: also need to have a backup and stop reading from stream after max size is reached to
     * protect against malicious clients
     */

    /** TODO: need to extract the actual file type and determine if they are permissable */

    /// ItemDetailsCommand itemDetailsCommand=new ItemDetailsCommand()
    // DocumentCommand documentCommand = new DocumentCommand(null, null, entityType, entityId, name,
    // fileDetails.getFileName(), fileSize,
    ///     bodyPart.getMediaType().toString(), description, null);

    // Long documentId = this.documentWritePlatformService.createDocument(documentCommand,
    // inputStream);

    // return this.toApiJsonSerializer.serialize(CommandProcessingResult.resourceResult(1, null));
    return null;
  }