Package org.zanata.model

Examples of org.zanata.model.HProjectIteration


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

        HProjectIteration iteration =
                projectIterationDAO.getBySlug(projectSlug, iterationSlug);

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

        Map<String, TransUnitCount> transUnitIterationStats =
                projectIterationDAO.getAllStatisticsForContainer(iteration
                        .getId());
        Map<String, TransUnitWords> wordIterationStats =
                projectIterationDAO
                        .getAllWordStatsStatistics(iteration.getId());

        ContainerTranslationStatistics iterationStats =
                new ContainerTranslationStatistics();
        iterationStats.setId(iterationSlug);
        iterationStats.addRef(new Link(URI.create(zPathService
                .generatePathForProjectIteration(iteration)), "statSource",
                "PROJ_ITER"));
        long iterationTotalMssgs =
                projectIterationDAO
                        .getTotalMessageCountForIteration(iteration.getId());
        long iterationTotalWords =
                projectIterationDAO.getTotalWordCountForIteration(iteration
                        .getId());

        for (LocaleId locId : localeIds) {
            // trans unit level stats
            TransUnitCount count = transUnitIterationStats.get(locId.getId());
            // Stats might not return anything if nothing is translated
            if (count == null) {
                count = new TransUnitCount(0, 0, (int) iterationTotalMssgs);
            }

            HTextFlowTarget target =
                    localeServiceImpl.getLastTranslated(projectSlug,
                            iterationSlug, locId);

            String lastModifiedBy = "";
            Date lastModifiedDate = null;

            if (target != null) {
                lastModifiedDate = target.getLastChanged();
                if (target.getLastModifiedBy() != null) {
                    lastModifiedBy =
                            target.getLastModifiedBy().getAccount()
                                    .getUsername();
                }
            }

            TransUnitWords wordCount = wordIterationStats.get(locId.getId());
            if (wordCount == null) {
                wordCount = new TransUnitWords(0, 0, (int) iterationTotalWords);
            }

            TranslationStatistics transUnitStats =
                    getMessageStats(count, locId, lastModifiedDate,
                            lastModifiedBy);
            transUnitStats.setRemainingHours(StatisticsUtil
                    .getRemainingHours(wordCount));
            iterationStats.addStats(transUnitStats);

            // word level stats
            if (includeWordStats) {
                TranslationStatistics wordsStats =
                        getWordsStats(wordCount, locId, lastModifiedDate,
                                lastModifiedBy);
                wordsStats.setRemainingHours(StatisticsUtil
                        .getRemainingHours(wordCount));
                iterationStats.addStats(wordsStats);
            }
        }

        // TODO Do in a single query
        if (includeDetails) {
            for (String docId : iteration.getDocuments().keySet()) {
                iterationStats.addDetailedStats(this.getStatistics(projectSlug,
                        iterationSlug, docId, includeWordStats, locales));
            }
        }
View Full Code Here


     */
    @Override
    public ContributionStatistics getContributionStatistics(String projectSlug,
            String versionSlug, String username, String dateRangeParam) {

        HProjectIteration version =
                projectIterationDAO.getBySlug(projectSlug, versionSlug);
        if (version == null || version.getStatus() == EntityStatus.OBSOLETE ||
                version.getProject().getStatus() == EntityStatus.OBSOLETE) {
            throw new NoSuchEntityException(projectSlug + "/" + versionSlug);
        }

        HPerson person = personDAO.findByUsername(username);
        if (person == null) {
            throw new NoSuchEntityException(username);
        }

        String[] dateRange = dateRangeParam.split("\\.\\.");
        if (dateRange.length != 2) {
            throw new InvalidDateParamException(dateRangeParam);
        }

        Date fromDate, toDate;

        try {
            fromDate = DateUtil.getDate(dateRange[0], DATE_FORMAT);
            toDate = DateUtil.getDate(dateRange[1], DATE_FORMAT);

            fromDate = DateUtil.getStartOfDay(fromDate);
            toDate = DateUtil.getEndOfTheDay(toDate);

            if (fromDate.after(toDate) || !DateUtil.isDatesInRange(fromDate,
                    toDate, MAX_STATS_DAYS)) {
                throw new InvalidDateParamException(dateRangeParam);
            }
        } catch (IllegalArgumentException e) {
            throw new InvalidDateParamException(dateRangeParam);
        }

        LocaleStatistics localeStatistics = new LocaleStatistics();

        List<Object[]> data =
                textFlowTargetHistoryDAO.getUserTranslationHistoryInVersion(
                        version.getId(), person.getId(), fromDate, toDate);

        for (Object[] entry : data) {
            int count = ((BigDecimal) entry[0]).intValue();
            ContentState state = ContentState.values()[(int) entry[1]];
            LocaleId localeId = new LocaleId(entry[2].toString());
View Full Code Here

    public void setup() {
        MockitoAnnotations.initMocks(this);
        documentService = new DocumentServiceImpl();
        documentService.init(projectIterationDAO, documentDAO, msgs);

        HProjectIteration version = Mockito.mock(HProjectIteration.class);
        HProject project = Mockito.mock(HProject.class);
        HDocument document = Mockito.mock(HDocument.class);

        webHooks = Lists.newArrayList();
        webHooks.add(new WebHook(project, "http://test.com"));
        webHooks.add(new WebHook(project, "http://test1.com"));

        when(projectIterationDAO.findById(versionId)).thenReturn(version);
        when(version.getProject()).thenReturn(project);
        when(version.getSlug()).thenReturn(versionSlug);
        when(project.getSlug()).thenReturn(projectSlug);
        when(project.getWebHooks()).thenReturn(webHooks);
        when(documentDAO.getById(docId)).thenReturn(document);
        when(document.getDocId()).thenReturn(docIdString);
View Full Code Here

        ProjectIterationDAO iterationDAO =
                seam.autowire(ProjectIterationDAO.class);
        LocaleDAO localeDAO = seam.autowire(LocaleDAO.class);

        // Get the project iteration
        HProjectIteration projectIteration;
        if (execution.projectMatches) {
            projectIteration =
                    iterationDAO.getBySlug("same-project", "different-version");
        } else {
            projectIteration =
                    iterationDAO.getBySlug("different-project",
                            "different-version");
        }
        assert projectIteration != null;

        // Set require translation review
        projectIteration
                .setRequireTranslationReview(execution.requireTranslationReview);

        // Change all targets to have the execution's match state
        for (HDocument doc : projectIteration.getDocuments().values()) {
            for (HTextFlow tf : doc.getAllTextFlows().values()) {
                for (HTextFlowTarget tft : tf.getTargets().values()) {
                    tft.setState(execution.matchState);
                }
            }
        }

        // Create the document
        HDocument doc = new HDocument();
        doc.setContentType(ContentType.TextPlain);
        doc.setLocale(localeDAO.findByLocaleId(LocaleId.EN_US));
        doc.setProjectIteration(projectIteration);
        if (execution.documentMatches) {
            doc.setFullPath("/same/document");
        } else {
            doc.setFullPath("/different/document");
        }
        projectIteration.getDocuments().put(doc.getDocId(), doc);

        // Create the text Flow
        HTextFlow textFlow = new HTextFlow();
        textFlow.setContents("Source Content"); // Source content matches
        textFlow.setPlural(false);
View Full Code Here

        ProjectIterationDAO projectIterationDAO =
                seam.autowire(ProjectIterationDAO.class);
        ProjectDAO projectDAO = seam.autowire(ProjectDAO.class);

        // Make versions and projects obsolete
        HProjectIteration version =
                projectIterationDAO.getBySlug("same-project", "same-version");
        assert version != null;
        version.setStatus(EntityStatus.OBSOLETE);
        projectIterationDAO.makePersistent(version);

        HProject project = projectDAO.getBySlug("different-project");
        assert project != null;
        project.setStatus(EntityStatus.OBSOLETE);
View Full Code Here

        ProjectIterationDAO projectIterationDAO =
                seam.autowire(ProjectIterationDAO.class);
        DocumentDAO documentDAO = seam.autowire(DocumentDAO.class);

        // Make all documents obsolete
        HProjectIteration version =
                projectIterationDAO.getBySlug("same-project", "same-version");
        assert version != null;
        for (HDocument doc : version.getDocuments().values()) {
            doc.setObsolete(true);
            documentDAO.makePersistent(doc);
        }

        ProjectDAO projectDAO = seam.autowire(ProjectDAO.class);
View Full Code Here

    @PerformanceProfiling
    // ideally change persistence.xml to use a local mysql database and monitor general log etc.
    public void transferFromResource() {
        HLocale locale = EntityMakerBuilder.builder().addConstructorParameterMaker(HLocale.class, 0, FixedValueMaker.fix(LocaleId.ES)).build()
                .makeAndPersist(getEm(), HLocale.class);
        HProjectIteration iteration =
                EntityMakerBuilder
                        .builder()
                        .addFieldOrPropertyMaker(
                                HProject.class, "sourceViewURL",
                                FixedValueMaker.EMPTY_STRING_MAKER).build()
View Full Code Here

        softly.assertThat(
                granter.shouldInvokeGranter(
                        "my-action", new HProject())).isTrue();
        softly.assertThat(
                granter.shouldInvokeGranter(
                        null, new HProjectIteration())).isFalse();
        softly.assertThat(
                granter.shouldInvokeGranter(
                        "my-action", new HProjectIteration())).isFalse();
        softly.assertAll();
    }
View Full Code Here

                                "evaluatesForMultiTarget"));

        assertThat(
                granter.shouldInvokeGranter(
                        "multi-target-action", new HLocale(), new HProject(),
                        new HProjectIteration(), new StringBuilder()
                        )).isTrue();
    }
View Full Code Here

    @Test
    public void alwaysGrantWithMultipleArguments() throws Exception {
        assertThat(complexPermissionEvaluator
                .checkPermission("always-grant", new HProject(), "A string",
                        new HProjectIteration())).isTrue();
    }
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.