Package org.zanata.model

Examples of org.zanata.model.HProjectIteration


    @Override
    public Map<String, String> getIterationCustomizedLocalesItems(
            String projectSlug, String iterationSlug) {
        Map<String, String> customizedItems = Maps.newTreeMap();
        HProjectIteration iteration =
                projectIterationDAO.getBySlug(projectSlug, iterationSlug);
        if (iteration != null && iteration.isOverrideLocales()) {
            Set<HLocale> locales = iteration.getCustomizedLocales();
            for (HLocale op : locales) {
                String name = getDescript(op);
                customizedItems.put(name, name);
            }
        }
View Full Code Here


            // Source locale
            // NB: Assume the first document's locale, or the same target locale
            // if there are no documents
            // TODO Move source locale to the Project iteration level
            LocaleId sourceLocaleId = localeId;
            HProjectIteration projectIteration =
                    projectIterationDAO.getBySlug(projectSlug, iterationSlug);
            if (!projectIteration.getDocuments().isEmpty()) {
                sourceLocaleId =
                        projectIteration.getDocuments().values().iterator()
                                .next().getLocale().getLocaleId();
            }

            // Content query for source
            String sourceAnalyzerName =
View Full Code Here

        // single locale check - assumes update requests are all from the same
        // project-iteration
        HTextFlow sampleHTextFlow =
                entityManager.find(HTextFlow.class, translationRequests.get(0)
                        .getTransUnitId().getValue());
        HProjectIteration projectIteration =
                sampleHTextFlow.getDocument().getProjectIteration();
        HLocale hLocale = validateLocale(localeId, projectIteration);

        // single permission check - assumes update requests are all from same
        // project
        validateReviewPermissionIfApplicable(translationRequests,
                projectIteration, hLocale);

        for (TransUnitUpdateRequest request : translationRequests) {
            HTextFlow hTextFlow =
                    entityManager.find(HTextFlow.class, request
                            .getTransUnitId().getValue());

            TranslationResultImpl result = new TranslationResultImpl();

            if (runValidation) {
                String validationMessage =
                        validateTranslations(request.getNewContentState(),
                                projectIteration, request.getTransUnitId()
                                        .toString(), hTextFlow.getContents(),
                                request.getNewContents());

                if (!StringUtils.isEmpty(validationMessage)) {
                    log.warn(validationMessage);
                    result.isSuccess = false;
                    result.errorMessage = validationMessage;
                    continue;
                }
            }

            HTextFlowTarget hTextFlowTarget =
                    textFlowTargetDAO.getOrCreateTarget(hTextFlow, hLocale);
            // if hTextFlowTarget is created, any further hibernate fetch will
            // trigger an implicit flush
            // (which will save this target even if it's not fully ready!!!)
            if (request.hasTargetComment()) {
                // FIXME this creates orphan comments, and replaces identical
                // comments with copies
                hTextFlowTarget.setComment(new HSimpleComment(request
                        .getTargetComment()));
            }

            result.baseVersion = hTextFlowTarget.getVersionNum();
            result.baseContentState = hTextFlowTarget.getState();

            if (request.getBaseTranslationVersion() == hTextFlowTarget
                    .getVersionNum()) {
                try {
                    int nPlurals = getNumPlurals(hLocale, hTextFlow);
                    result.targetChanged =
                            translate(hTextFlowTarget,
                                    request.getNewContents(),
                                    request.getNewContentState(), nPlurals,
                                    projectIteration
                                            .getRequireTranslationReview());
                    result.isSuccess = true;
                } catch (HibernateException e) {
                    result.isSuccess = false;
                    log.warn("HibernateException while translating");
View Full Code Here

    public List<String> translateAllInDoc(final String projectSlug,
            final String iterationSlug, final String docId,
            final LocaleId locale, final TranslationsResource translations,
            final Set<String> extensions, final MergeType mergeType,
            AsyncTaskHandle handle) {
        final HProjectIteration hProjectIteration =
                projectIterationDAO.getBySlug(projectSlug, iterationSlug);

        if (hProjectIteration == null) {
            throw new ZanataServiceException("Version '" + iterationSlug
                    + "' for project '" + projectSlug + "' ");
        }

        if (mergeType == MergeType.IMPORT) {
            identity.checkPermission("import-translation", hProjectIteration);
        }

        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);
View Full Code Here

        protected Boolean work() throws Exception {
            boolean changed = false;

            // we need a fresh object in this session,
            // so that it can lazily load associated objects
            HProjectIteration iteration =
                    projectIterationDAO.findById(projectIterationId);
            Map<String, HTextFlow> resIdToTextFlowMap = textFlowDAO.getByDocumentAndResIds(document, Lists.transform(
                    batch, new Function<TextFlowTarget, String>() {

                        @Override
View Full Code Here

    @Override
    @Transactional
    public HDocument saveDocument(String projectSlug, String iterationSlug,
            Resource sourceDoc, Set<String> extensions, boolean copyTrans) {
        // Only active iterations allow the addition of a document
        HProjectIteration hProjectIteration =
                projectIterationDAO.getBySlug(projectSlug, iterationSlug);

        // 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 |=
View Full Code Here

        boolean shouldPublish =
                hasContentStateReachedMilestone(event.getOldStats(),
                        event.getNewStats(), contentStates, percentMilestone);

        if (shouldPublish) {
            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 HProject checkWorkspaceStatus(WorkspaceId workspaceId) {
        identity.checkLoggedIn();
        HProject project =
                projectDAO.getBySlug(workspaceId.getProjectIterationId()
                        .getProjectSlug());
        HProjectIteration projectIteration =
                projectIterationDAO.getBySlug(workspaceId
                        .getProjectIterationId().getProjectSlug(), workspaceId
                        .getProjectIterationId().getIterationSlug());

        if (projectIterationIsInactive(project.getStatus(),
                projectIteration.getStatus())) {
            throw new AuthorizationException("Project or version is read-only");
        }
        return project;
    }
View Full Code Here

    @Override
    public Collection<ValidationAction> getValidationActions(
            String projectSlug, String versionSlug) {
        if (!StringUtils.isEmpty(projectSlug)
                && !StringUtils.isEmpty(versionSlug)) {
            HProjectIteration version =
                    projectIterationDAO.getBySlug(projectSlug, versionSlug);
            return getValidationActions(version);
        } else if (!StringUtils.isEmpty(projectSlug)) {
            return getValidationActions(projectSlug);
        }
View Full Code Here

    }

    @Override
    public boolean isPoDocument(String projectSlug, String iterationSlug,
            String docId) {
        HProjectIteration projectIteration =
                projectIterationDAO.getBySlug(projectSlug, iterationSlug);
        ProjectType projectType = projectIteration.getProjectType();
        if (projectType == null) {
            projectType = projectIteration.getProject().getDefaultProjectType();
        }
        if (projectType == ProjectType.Gettext
                || projectType == ProjectType.Podir) {
            return true;
        }
View Full Code Here

TOP

Related Classes of org.zanata.model.HProjectIteration

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.