Package org.zanata.model

Examples of org.zanata.model.HDocument


        return idAsString + "." + extension;
    }

    // TODO damason: put this in a more appropriate location
    private static GlobalDocumentId getGlobalId(HRawDocument rawDocument) {
        HDocument document = rawDocument.getDocument();
        HProjectIteration version = document.getProjectIteration();
        HProject project = version.getProject();

        GlobalDocumentId id =
                new GlobalDocumentId(project.getSlug(), version.getSlug(),
                        document.getDocId());

        return id;
    }
View Full Code Here


        }
    }

    @Override
    public boolean hasPersistedDocument(GlobalDocumentId id) {
        HDocument doc = documentDAO.getByGlobalId(id);
        if (doc != null) {
            HRawDocument rawDocument = doc.getRawDocument();
            return rawDocument != null
                    && getFileForRawDocument(rawDocument).exists();
        }
        return false;
    }
View Full Code Here

                || getVersion().getStatus() == EntityStatus.ACTIVE;
    }

    @Restrict("#{versionHomeAction.documentRemovalAllowed}")
    public void deleteDocument(Long docId) {
        HDocument doc = documentDAO.getById(docId);
        documentServiceImpl.makeObsolete(doc);
        resetPageData();
        conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
                doc.getDocId() + " has been removed.");
    }
View Full Code Here

            docId =
                    translationFileServiceImpl.generateDocId(
                            sourceFileUpload.getDocumentPath(),
                            sourceFileUpload.getFileName());
        }
        HDocument existingDoc =
                documentDAO.getByProjectIterationAndDocId(projectSlug,
                        versionSlug, docId);
        boolean docExists = existingDoc != null;
        boolean useOfflinePo = docExists && !isPoDocument(docId);
View Full Code Here

                    "Error generating hash for uploaded document " + fileName
                            + ".");
            return;
        }

        HDocument document = null;
        try {
            Resource doc;
            if (docId == null) {
                doc =
                        translationFileServiceImpl.parseAdapterDocumentFile(
View Full Code Here

    private void prepareTransUnitUpdatedEvent(int previousVersionNum,
            ContentState previousState, HTextFlowTarget target) {
        LocaleId localeId = target.getLocaleId();
        HTextFlow textFlow = target.getTextFlow();
        HDocument document = textFlow.getDocument();
        HProjectIteration projectIteration = document.getProjectIteration();
        String iterationSlug = projectIteration.getSlug();
        String projectSlug = projectIteration.getProject().getSlug();
        ProjectType projectType = projectIteration.getProjectType();

        WorkspaceId workspaceId =
                new WorkspaceId(new ProjectIterationId(projectSlug,
                        iterationSlug, projectType), localeId);
        Optional<TranslationWorkspace> workspaceOptional =
                translationWorkspaceManager.tryGetWorkspace(workspaceId);
        if (!workspaceOptional.isPresent()) {
            return;
        }

        TransUnitTransformer transUnitTransformer =
                serviceLocator.getInstance(TransUnitTransformer.class);
        TransUnit transUnit =
                transUnitTransformer.transform(textFlow, target,
                        target.getLocale());

        DocumentId documentId =
                new DocumentId(document.getId(), document.getDocId());
        int wordCount = textFlow.getWordCount().intValue();

        TransUnitUpdateInfo updateInfo =
                createTransUnitUpdateInfo(transUnit, documentId, wordCount,
                        previousVersionNum, previousState);
View Full Code Here

        public int compare(HDocument o1, HDocument o2) {
            SortingType.SortOption selectedSortOption =
                    sortingType.getSelectedSortOption();

            if (!selectedSortOption.isAscending()) {
                HDocument temp = o1;
                o1 = o2;
                o2 = temp;
            }

            if (selectedSortOption.equals(SortingType.SortOption.ALPHABETICAL)) {
View Full Code Here

    @Override
    public Response downloadSourceFile(String projectSlug,
            String iterationSlug, String fileType, String docId) {
        // TODO scan (again) for virus
        HDocument document =
                documentDAO.getByProjectIterationAndDocId(projectSlug,
                        iterationSlug, docId);
        if (document == null) {
            return Response.status(Status.NOT_FOUND).build();
        }

        if (FILETYPE_RAW_SOURCE_DOCUMENT.equals(fileType)) {
            if (document.getRawDocument() == null) {
                return Response.status(Status.NOT_FOUND).build();
            }
            InputStream fileContents;
            try {
                fileContents =
                        filePersistService
                                .getRawDocumentContentAsStream(document
                                        .getRawDocument());
            } catch (RawDocumentContentAccessException e) {
                e.printStackTrace();
                return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e)
                        .build();
            }
            StreamingOutput output =
                    new InputStreamStreamingOutput(fileContents);
            return Response
                    .ok()
                    .header("Content-Disposition",
                            "attachment; filename=\"" + document.getName()
                                    + "\"").entity(output).build();
        } else if ("pot".equals(fileType)
                || FILE_TYPE_OFFLINE_PO_TEMPLATE.equals(fileType)) {
            // Note: could give 404 or unsupported media type for "pot" in
            // non-po projects,
            // and suggest using offlinepo
            Resource res = resourceUtils.buildResource(document);
            StreamingOutput output =
                    new POTStreamingOutput(res,
                            FILE_TYPE_OFFLINE_PO_TEMPLATE.equals(fileType));
            return Response
                    .ok()
                    .header("Content-Disposition",
                            "attachment; filename=\"" + document.getName()
                                    + ".pot\"").type(MediaType.TEXT_PLAIN)
                    .entity(output).build();
        } else {
            return Response.status(Status.UNSUPPORTED_MEDIA_TYPE).build();
        }
View Full Code Here

            String iterationSlug, String locale, String fileType, String docId) {
        GlobalDocumentId id =
                new GlobalDocumentId(projectSlug, iterationSlug, docId);
        // TODO scan (again) for virus
        final Response response;
        HDocument document =
                this.documentDAO.getByProjectIterationAndDocId(projectSlug,
                        iterationSlug, docId);

        if (document == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else if ("po".equals(fileType)
                || FILE_TYPE_OFFLINE_PO.equals(fileType)) {
            // Note: could return 404 or Unsupported media type for "po" in
            // non-po projects,
            // and suggest to use offlinepo
            final Set<String> extensions = new HashSet<String>();
            extensions.add("gettext");
            extensions.add("comment");

            // Perform translation of Hibernate DTOs to JAXB DTOs
            TranslationsResource transRes =
                    (TranslationsResource) this.translatedDocResourceService
                            .getTranslations(docId, new LocaleId(locale),
                                    extensions, true, null).getEntity();
            Resource res = this.resourceUtils.buildResource(document);

            StreamingOutput output =
                    new POStreamingOutput(res, transRes,
                            FILE_TYPE_OFFLINE_PO.equals(fileType));
            response =
                    Response.ok()
                            .header("Content-Disposition",
                                    "attachment; filename=\""
                                            + document.getName() + ".po\"")
                            .type(MediaType.TEXT_PLAIN).entity(output).build();
        } else if (FILETYPE_TRANSLATED_APPROVED.equals(fileType)
                || FILETYPE_TRANSLATED_APPROVED_AND_FUZZY.equals(fileType)) {
            if (!filePersistService.hasPersistedDocument(id)) {
                return Response.status(Status.NOT_FOUND).build();
            }
            final Set<String> extensions = Collections.<String> emptySet();
            TranslationsResource transRes =
                    (TranslationsResource) this.translatedDocResourceService
                            .getTranslations(docId, new LocaleId(locale),
                                    extensions, true, null).getEntity();
            // Filter to only provide translated targets. "Preview" downloads
            // include fuzzy.
            // New list is used as transRes list appears not to be a modifiable
            // implementation.
            Map<String, TextFlowTarget> translations =
                    new HashMap<String, TextFlowTarget>();
            boolean useFuzzy =
                    FILETYPE_TRANSLATED_APPROVED_AND_FUZZY.equals(fileType);
            for (TextFlowTarget target : transRes.getTextFlowTargets()) {
                // TODO rhbz953734 - translatedDocResourceService will map
                // review content state to old state. For now this is
                // acceptable. Once we have new REST options, we should review
                // this
                if (target.getState() == ContentState.Approved
                        || (useFuzzy && target.getState() == ContentState.NeedReview)) {
                    translations.put(target.getResId(), target);
                }
            }

            HDocument hDocument =
                    documentDAO.getByProjectIterationAndDocId(projectSlug,
                            iterationSlug, docId);
            InputStream inputStream;
            try {
                inputStream =
                        filePersistService
                                .getRawDocumentContentAsStream(hDocument
                                        .getRawDocument());
            } catch (RawDocumentContentAccessException e) {
                return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e)
                        .build();
            }
            File tempFile =
                    translationFileServiceImpl.persistToTempFile(inputStream);
            String name = projectSlug + ":" + iterationSlug + ":" + docId;
            // TODO damason: this file is not transmitted, but used to generate
            // a file later
            // the generated file should be scanned instead
            virusScanner.scan(tempFile, name);
            URI uri = tempFile.toURI();
            FileFormatAdapter adapter =
                    translationFileServiceImpl.getAdapterFor(hDocument
                            .getRawDocument().getType());
            String rawParamString =
                    hDocument.getRawDocument().getAdapterParameters();
            Optional<String> params =
                    Optional.<String> fromNullable(Strings
                            .emptyToNull(rawParamString));
            StreamingOutput output =
                    new FormatAdapterStreamingOutput(uri, translations, locale,
View Full Code Here

            log.warn("File failed virus scan: {}", e.getMessage());
            throw new ChunkUploadException(Status.BAD_REQUEST,
                    "Uploaded file did not pass virus scan");
        }

        HDocument document;
        Optional<String> params;
        params =
                Optional.fromNullable(Strings.emptyToNull(uploadForm
                        .getAdapterParams()));
        if (!params.isPresent()) {
View Full Code Here

TOP

Related Classes of org.zanata.model.HDocument

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.