Package org.zanata.model

Examples of org.zanata.model.HDocument


    @Override
    public List<HTextFlow> findTextFlows(WorkspaceId workspace, DocumentId doc,
            FilterConstraints constraints) {
        List<String> documentPaths = new ArrayList<String>(1);
        HDocument document = documentDAO.getById(doc.getId());
        documentPaths.add(document.getDocId());

        return this.findTextFlows(workspace, documentPaths, constraints);
    }
View Full Code Here


            final HCopyTransOptions options,
            Optional<CopyTransTaskHandle> taskHandleOpt,
            boolean requireTranslationReview) {

        try {
            HDocument hDocument = documentDAO.findById(document.getId());
            List<HTextFlow> docTextFlows = hDocument.getTextFlows();
            int batchEnd =
                    Math.min(batchStart + batchLength, docTextFlows.size());
            int batchSize = batchEnd - batchStart;
            List<HTextFlow> copyTargets =
                    docTextFlows.subList(batchStart, batchEnd);
View Full Code Here

        // Check permission
        identity.checkPermission(hProjectIteration, "import-template");

        String docId = sourceDoc.getName();

        HDocument document =
                documentDAO.getByDocIdAndIteration(hProjectIteration, docId);
        HLocale hLocale =
                this.localeServiceImpl
                        .validateSourceLocale(sourceDoc.getLang());

        boolean changed = false;
        int nextDocRev;
        if (document == null) { // must be a create operation
            nextDocRev = 1;
            changed = true;
            // TODO check that entity name matches id parameter
            document =
                    new HDocument(sourceDoc.getName(),
                            sourceDoc.getContentType(), hLocale);
            document.setProjectIteration(hProjectIteration);
            hProjectIteration.getDocuments().put(docId, document);
            document = documentDAO.makePersistent(document);
        } else if (document.isObsolete()) { // must also be a create operation
            nextDocRev = document.getRevision() + 1;
            changed = true;
            document.setObsolete(false);
            // not sure if this is needed
            hProjectIteration.getDocuments().put(docId, document);
        } else { // must be an update operation
            nextDocRev = document.getRevision() + 1;
        }

        changed |=
                resourceUtils.transferFromResource(sourceDoc, document,
                        extensions, hLocale, nextDocRev);
        documentDAO.flush();

        long actorId = authenticatedAccount.getPerson().getId();
        if (changed) {
            if (Events.exists()) {
                Events.instance().raiseTransactionSuccessEvent(
                        DocumentUploadedEvent.EVENT_NAME,
                        new DocumentUploadedEvent(actorId, document.getId(),
                                true, hLocale.getLocaleId()));
            }
            clearStatsCacheForUpdatedDocument(document);
        }
View Full Code Here

            HProjectIteration version =
                    projectIterationDAO.findById(event.getProjectIterationId());
            HProject project = version.getProject();

            if (!project.getWebHooks().isEmpty()) {
                HDocument document = documentDAO.getById(event.getDocumentId());
                DocumentMilestoneEvent milestoneEvent =
                        new DocumentMilestoneEvent(project.getSlug(),
                                version.getSlug(), document.getDocId(),
                                event.getLocaleId(), message);
                for (WebHook webHook : project.getWebHooks()) {
                    publishDocumentMilestoneEvent(webHook, milestoneEvent);
                }
            }
View Full Code Here

    public boolean runDocValidations(Long hDocId,
            List<ValidationId> validationIds, LocaleId localeId) {
        log.debug("Start runDocValidations {}", hDocId);
        Stopwatch stopwatch = new Stopwatch().start();

        HDocument hDoc = documentDAO.findById(hDocId, false);
        boolean hasError = documentHasWarningOrError(hDoc, validationIds, localeId);
        log.debug("Finished runDocValidations in " + stopwatch);
        return hasError;
    }
View Full Code Here

    }

    @Override
    public String getFileExtension(String projectSlug, String iterationSlug,
            String docPath, String docName) {
        HDocument doc =
                documentDAO.getByProjectIterationAndDocId(projectSlug,
                        iterationSlug, docPath + docName);
        return doc.getRawDocument().getType().getExtension();
    }
View Full Code Here

                || projectType == ProjectType.Podir) {
            return true;
        }

        if (projectType == ProjectType.File) {
            HDocument doc =
                    documentDAO.getByDocIdAndIteration(projectIteration, docId);
            if (doc.getRawDocument() == null) {
                // po is the only format in File projects for which no raw
                // document is stored
                return true;
            }

            // additional check in case we do start storing raw documents for po
            DocumentType docType = doc.getRawDocument().getType();
            return docType == GETTEXT_PORTABLE_OBJECT
                    || docType == GETTEXT_PORTABLE_OBJECT_TEMPLATE;
        }
        return false;
    }
View Full Code Here

        Map<Long, HTextFlow> tfMap = Maps.newHashMap();

        List<HTextFlow> textFlows = textFlowDAO.getTextFlowsByDocumentId(
                documentId, batchStart, batchLength);

        HDocument newDocument = documentDAO.getById(newDocumentId);
        for (HTextFlow textFlow : textFlows) {
            HTextFlow newTextFlow =
                    copyVersionService.copyTextFlow(newDocument,
                            textFlow);

            newDocument.getTextFlows().add(newTextFlow);
            newDocument.getAllTextFlows()
                    .put(newTextFlow.getResId(), newTextFlow);
            tfMap.put(textFlow.getId(), newTextFlow);
        }
        documentDAO.makePersistent(newDocument);
        documentDAO.flush();
View Full Code Here

        }

        ResourceUtils.validateExtensions(extensions);

        log.debug("pass evaluate");
        final HDocument document =
                documentDAO.getByDocIdAndIteration(hProjectIteration, docId);
        if (document == null || document.isObsolete()) {
            throw new ZanataServiceException("A document was not found.", 404);
        }

        log.debug("start put translations entity:{}", translations);

        boolean changed = false;

        final HLocale hLocale =
                localeServiceImpl.validateLocaleByProjectIteration(locale,
                        projectSlug, iterationSlug);
        final Optional<AsyncTaskHandle> handleOp =
                Optional.fromNullable(handle);

        if (handleOp.isPresent()) {
            handleOp.get().setMaxProgress(
                    translations.getTextFlowTargets().size());
        }

        try {
            changed |= new Work<Boolean>() {
                @Override
                protected Boolean work() throws Exception {
                    // handle extensions
                    boolean changed =
                            resourceUtils
                                    .transferFromTranslationsResourceExtensions(
                                            translations.getExtensions(true),
                                            document, extensions, hLocale,
                                            mergeType);
                    return changed;
                }
            }.workInTransaction();
        } catch (Exception e) {
            throw new ZanataServiceException("Error during translation.", 500,
                    e);
        }

        // NB: removedTargets only applies for MergeType.IMPORT
        final Collection<HTextFlowTarget> removedTargets =
                new HashSet<HTextFlowTarget>();
        final List<String> warnings = new ArrayList<String>();

        if (mergeType == MergeType.IMPORT) {
            for (HTextFlow textFlow : document.getTextFlows()) {
                HTextFlowTarget hTarget =
                        textFlow.getTargets().get(hLocale.getId());
                if (hTarget != null) {
                    removedTargets.add(hTarget);
                }
            }
        }

        // Break the target into batches
        List<List<TextFlowTarget>> batches =
                Lists.partition(translations.getTextFlowTargets(), BATCH_SIZE);

        for (final List<TextFlowTarget> batch : batches) {
            try {
                SaveBatchWork work = new SaveBatchWork();
                work.setExtensions(extensions);
                work.setWarnings(warnings);
                work.setLocale(hLocale);
                work.setDocument(document);
                work.setMergeType(mergeType);
                work.setRemovedTargets(removedTargets);
                work.setHandleOp(handleOp);
                work.setProjectIterationId(hProjectIteration.getId());
                work.setBatch(batch);
                changed |= work.workInTransaction();
            } catch (Exception e) {
                throw new ZanataServiceException("Error during translation.",
                        500, e);
            }

        }

        if (changed || !removedTargets.isEmpty()) {
            try {
                new Work<Void>() {
                    @Override
                    protected Void work() throws Exception {
                        for (HTextFlowTarget target : removedTargets) {
                            target =
                                    textFlowTargetDAO.findById(target.getId(),
                                            true); // need to refresh from
                                                   // persistence
                            target.clear();
                        }
                        textFlowTargetDAO.flush();

                        documentDAO.flush();
                        return null;
                    }
                }.workInTransaction();

                if (Events.exists()) {
                    Long actorId = authenticatedAccount.getPerson().getId();
                    Events.instance().raiseEvent(
                            DocumentUploadedEvent.EVENT_NAME,
                            new DocumentUploadedEvent(actorId,
                                    document.getId(), false, hLocale
                                            .getLocaleId()));
                }
            } catch (Exception e) {
                throw new ZanataServiceException("Error during translation.",
                        500, e);
View Full Code Here

            for (int i = 0; i < locales.length; i++) {
                localeIds[i] = new LocaleId(locales[i]);
            }
        }

        HDocument document =
                documentDAO.getByProjectIterationAndDocId(projectSlug,
                        iterationSlug, docId);

        if (document == null) {
            throw new NoSuchEntityException(projectSlug + "/" + iterationSlug
                    + "/" + docId);
        }

        ContainerTranslationStatistics docStatistics =
                new ContainerTranslationStatistics();
        docStatistics.setId(docId);
        docStatistics.addRef(new Link(URI.create(zPathService
                .generatePathForDocument(document)), "statSource", "DOC"));

        for (LocaleId localeId : localeIds) {
            ContainerTranslationStatistics docStats =
                    getDocStatistics(document.getId(), localeId);

            DocumentStatus docStatus =
                    translationStateCacheImpl.getDocumentStatus(
                            document.getId(), localeId);

            TranslationStatistics docWordStatistic =
                    docStats.getStats(localeId.getId(), StatUnit.WORD);
            TranslationStatistics docMsgStatistic =
                    docStats.getStats(localeId.getId(), StatUnit.MESSAGE);
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.