Package org.zanata.model

Examples of org.zanata.model.HDocumentUpload


        if (uploadForm.getUploadId() == null) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Form parameter 'uploadId' must be provided when this is not the first part.");
        }

        HDocumentUpload upload =
                documentUploadDAO.findById(uploadForm.getUploadId());
        if (upload == null) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "No incomplete uploads found for uploadId '"
                            + uploadForm.getUploadId() + "'.");
        }
        if (!upload.getDocId().equals(id.getDocId())) {
            throw new ChunkUploadException(Status.PRECONDITION_FAILED,
                    "Supplied uploadId '" + uploadForm.getUploadId()
                            + "' in request is not valid for document '"
                            + id.getDocId() + "'.");
        }
View Full Code Here


        }
    }

    protected HDocumentUpload saveUploadPart(GlobalDocumentId id,
            HLocale locale, DocumentFileUploadForm uploadForm) {
        HDocumentUpload upload;
        if (uploadForm.getFirst()) {
            upload = createMultipartUpload(id, uploadForm, locale);
        } else {
            upload = documentUploadDAO.findById(uploadForm.getUploadId());
        }
View Full Code Here

    private HDocumentUpload createMultipartUpload(GlobalDocumentId id,
            DocumentFileUploadForm uploadForm, HLocale locale) {
        HProjectIteration projectIteration =
                projectIterationDAO.getBySlug(id.getProjectSlug(),
                        id.getVersionSlug());
        HDocumentUpload newUpload = new HDocumentUpload();
        newUpload.setProjectIteration(projectIteration);
        newUpload.setDocId(id.getDocId());
        newUpload.setType(DocumentType.typeFor(uploadForm.getFileType()));
        // locale intentionally left null for source
        newUpload.setLocale(locale);
        newUpload.setContentHash(uploadForm.getHash());
        return newUpload;
    }
View Full Code Here

            if (isSinglePart(uploadForm)) {
                totalChunks = 1;
                tempFile = Optional.<File> absent();
            } else {
                if (!uploadForm.getLast()) {
                    HDocumentUpload upload =
                            util.saveUploadPart(id, locale, uploadForm);
                    totalChunks = upload.getParts().size();
                    return Response
                            .status(Status.ACCEPTED)
                            .entity(new ChunkUploadResponse(upload.getId(),
                                    totalChunks, true,
                                    "Chunk accepted, awaiting remaining chunks."))
                            .build();
                } else {
                    HDocumentUpload previousParts =
                            documentUploadDAO
                                    .findById(uploadForm.getUploadId());
                    totalChunks = previousParts.getParts().size();
                    totalChunks++; // add final part
                    tempFile =
                            Optional.of(util
                                    .combineToTempFileAndDeleteUploadRecord(
                                            previousParts,
View Full Code Here

        try {
            Optional<File> tempFile;
            int totalChunks;

            if (!uploadForm.getLast()) {
                HDocumentUpload upload =
                        util.saveUploadPart(id, NULL_LOCALE, uploadForm);
                totalChunks = upload.getParts().size();
                return Response
                        .status(Status.ACCEPTED)
                        .entity(new ChunkUploadResponse(upload.getId(),
                                totalChunks, true,
                                "Chunk accepted, awaiting remaining chunks."))
                        .build();
            }

            if (isSinglePart(uploadForm)) {
                totalChunks = 1;
                tempFile = Optional.<File> absent();
            } else {
                HDocumentUpload previousParts =
                        documentUploadDAO.findById(uploadForm.getUploadId());
                totalChunks = previousParts.getParts().size();
                totalChunks++; // add final part
                tempFile =
                        Optional.of(util
                                .combineToTempFileAndDeleteUploadRecord(
                                        previousParts,
View Full Code Here

                defaultUpload().first(false).uploadId(5L)
                        .docId("mismatched-id").build();
        mockLoggedIn();
        mockProjectAndVersionStatus();

        HDocumentUpload upload = new HDocumentUpload();
        upload.setDocId("correct-id");
        when(documentUploadDAO.findById(conf.uploadId)).thenReturn(upload);

        try {
            util.failIfUploadNotValid(conf.id, conf.uploadForm);
        } catch (ChunkUploadException e) {
View Full Code Here

            }
        }
    }

    public void canCombineUploadPartsInOrder() throws SQLException, IOException {
        HDocumentUpload upload = mockTwoPartUploadUsingHash(HASH_OF_ABCDEFGHI);

        InputStream finalPartStream =
                new ByteArrayInputStream("ghi".getBytes());
        File persistedFile = new File("test");
View Full Code Here

        assertThat(persistedContents, is("abcdefghi"));
        verify(session).delete(upload);
    }

    public void combineFailsOnHashMismatch() throws SQLException {
        HDocumentUpload upload = mockTwoPartUploadUsingHash("incorrect hash");
        InputStream finalPartStream =
                new ByteArrayInputStream("ghi".getBytes());

        DocumentFileUploadForm uploadForm = new DocumentFileUploadForm();
        uploadForm.setFileStream(finalPartStream);
View Full Code Here

                          "operation."));
        }
    }

    public void combineSetsHashWhenNoHashProvided() throws SQLException {
        HDocumentUpload upload = mockTwoPartUploadUsingHash("");
        InputStream finalPartStream =
                new ByteArrayInputStream("ghi".getBytes());

        DocumentFileUploadForm uploadForm = new DocumentFileUploadForm();
        uploadForm.setFileStream(finalPartStream);
View Full Code Here

        assertThat(uploadForm.getHash(), is(HASH_OF_ABCDEFGHI));
    }

    private HDocumentUpload mockTwoPartUploadUsingHash(String hash)
            throws SQLException {
        HDocumentUpload upload = new HDocumentUpload();
        upload.setContentHash(hash);

        HDocumentUploadPart part0 = new HDocumentUploadPart();
        when(partBlob0.getBinaryStream()).thenReturn(
                new ByteArrayInputStream("abc".getBytes()));
        part0.setContent(partBlob0);
        upload.getParts().add(part0);

        HDocumentUploadPart part1 = new HDocumentUploadPart();
        when(partBlob1.getBinaryStream()).thenReturn(
                new ByteArrayInputStream("def".getBytes()));
        part1.setContent(partBlob1);
        upload.getParts().add(part1);
        return upload;
    }
View Full Code Here

TOP

Related Classes of org.zanata.model.HDocumentUpload

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.