Examples of TranslationsResource


Examples of org.zanata.apicompat.rest.dto.resource.TranslationsResource

            @Override
            protected void onResponse(ClientResponse response) {
                assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
                assertJsonUnmarshal(response, TranslationsResource.class);

                TranslationsResource transRes =
                        jsonUnmarshal(response, TranslationsResource.class);
                assertThat(transRes.getTextFlowTargets().size(),
                        greaterThanOrEqualTo(3));

                // First Text Flow Target
                TextFlowTarget tft1 = transRes.getTextFlowTargets().get(0);
                assertThat(tft1.getResId(), is("tf2"));
                assertThat(tft1.getState(), is(ContentState.NeedReview));
                assertThat(tft1.getContents().get(0), is("mssgTrans1"));
                assertThat(
                        tft1.getExtensions(true)
                                .findByType(SimpleComment.class).getValue(),
                        is("Text Flow Target Comment 1"));
                assertThat(tft1.getTranslator().getName(), is("Sample User"));
                assertThat(tft1.getTranslator().getEmail(),
                        is("user1@localhost"));

                // Second Text Flow Target
                TextFlowTarget tft2 = transRes.getTextFlowTargets().get(1);
                assertThat(tft2.getResId(), is("tf3"));
                assertThat(tft2.getState(), is(ContentState.NeedReview));
                assertThat(tft2.getContents().get(0), is("mssgTrans2"));
                assertThat(
                        tft2.getExtensions(true)
                                .findByType(SimpleComment.class).getValue(),
                        is("Text Flow Target Comment 2"));
                assertThat(tft2.getTranslator().getName(), is("Sample User"));
                assertThat(tft2.getTranslator().getEmail(),
                        is("user1@localhost"));

                // First Text Flow Target
                TextFlowTarget tft3 = transRes.getTextFlowTargets().get(2);
                assertThat(tft3.getResId(), is("tf4"));
                assertThat(tft3.getState(), is(ContentState.NeedReview));
                assertThat(tft3.getContents().get(0), is("mssgTrans3"));
                assertThat(
                        tft3.getExtensions(true)
View Full Code Here

Examples of org.zanata.apicompat.rest.dto.resource.TranslationsResource

                        ITranslatedDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<TranslationsResource> response =
                translationsClient.getTranslations("my,path,document-2.txt",
                        LocaleId.EN_US, new StringSet(SimpleComment.ID));
        final TranslationsResource transRes = response.getEntity();

        assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
        assertThat(transRes.getTextFlowTargets().size(),
                greaterThanOrEqualTo(3));

        // Alter the translations
        transRes.getTextFlowTargets().get(0).setContents("Translated 1");
        transRes.getTextFlowTargets().get(1).setContents("Translated 2");
        transRes.getTextFlowTargets().get(2).setContents("Translated 3");

        transRes.getTextFlowTargets().get(0).setState(ContentState.Approved);
        transRes.getTextFlowTargets().get(1).setState(ContentState.Approved);
        transRes.getTextFlowTargets().get(2).setState(ContentState.Approved);

        transRes.getTextFlowTargets().get(0).getExtensions(true)
                .add(new SimpleComment("Translated Comment 1"));
        transRes.getTextFlowTargets().get(1).getExtensions(true)
                .add(new SimpleComment("Translated Comment 2"));
        transRes.getTextFlowTargets().get(2).getExtensions(true)
                .add(new SimpleComment("Translated Comment 3"));

        // Put the translations
        new ResourceRequest(
                getRestEndpointUrl("/projects/p/sample-project/iterations/i/1.0/r/my,path,document-2.txt/translations/"
                        + LocaleId.EN_US), "PUT", getAuthorizedEnvironment()) {
            @Override
            protected void prepareRequest(ClientRequest request) {
                request.queryParameter("ext", SimpleComment.ID);
                request.body(MediaType.APPLICATION_JSON, jsonMarshal(transRes));
            }

            @Override
            protected void onResponse(ClientResponse response) {
                assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
            }
        }.run();

        // Retrieve the translations once more to make sure they were changed
        // accordingly
        response =
                translationsClient.getTranslations("my,path,document-2.txt",
                        LocaleId.EN_US, new StringSet(SimpleComment.ID));
        TranslationsResource updatedTransRes = response.getEntity();

        assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
        assertThat(updatedTransRes.getTextFlowTargets().size(),
                greaterThanOrEqualTo(3));

        // First Text Flow Target
        TextFlowTarget tft1 = updatedTransRes.getTextFlowTargets().get(0);
        assertThat(tft1.getResId(), is("tf2"));
        assertThat(tft1.getState(), is(ContentState.Approved));
        assertThat(tft1.getContents().get(0), is("Translated 1"));
        assertThat(tft1.getExtensions(true).findByType(SimpleComment.class)
                .getValue(), is("Translated Comment 1"));
        assertThat(tft1.getTranslator().getName(), is("Sample User"));
        assertThat(tft1.getTranslator().getEmail(), is("user1@localhost"));

        // Second Text Flow Target
        TextFlowTarget tft2 = updatedTransRes.getTextFlowTargets().get(1);
        assertThat(tft2.getResId(), is("tf3"));
        assertThat(tft2.getState(), is(ContentState.Approved));
        assertThat(tft2.getContents().get(0), is("Translated 2"));
        assertThat(tft2.getExtensions(true).findByType(SimpleComment.class)
                .getValue(), is("Translated Comment 2"));
        assertThat(tft2.getTranslator().getName(), is("Sample User"));
        assertThat(tft2.getTranslator().getEmail(), is("user1@localhost"));

        // First Text Flow Target
        TextFlowTarget tft3 = updatedTransRes.getTextFlowTargets().get(2);
        assertThat(tft3.getResId(), is("tf4"));
        assertThat(tft3.getState(), is(ContentState.Approved));
        assertThat(tft3.getContents().get(0), is("Translated 3"));
        assertThat(tft3.getExtensions(true).findByType(SimpleComment.class)
                .getValue(), is("Translated Comment 3"));
View Full Code Here

Examples of org.zanata.rest.dto.resource.TranslationsResource

      final IFixedTranslationResources client = ProxyFactory.create(IFixedTranslationResources.class, URI);
      final ClientResponse<TranslationsResource> response = client.getTranslations(id, locale);

      if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.OK)
      {
        final TranslationsResource retValue = response.getEntity();
        return retValue;
      }
    }
    catch (final Exception ex)
    {
View Full Code Here

Examples of org.zanata.rest.dto.resource.TranslationsResource

    final ClientResponse<TranslationsResource> response = client.getTranslations("test", LocaleId.DE);

    if (response.getStatus() == 200)
    {

      final TranslationsResource entity = response.getEntity();

      final List<TextFlowTarget> targets = entity.getTextFlowTargets();

      for (final TextFlowTarget target : targets)
        System.out.println(target.getContent());
    }
    else
View Full Code Here

Examples of org.zanata.rest.dto.resource.TranslationsResource

                String projectSlug = params.get("projectSlug").getString();
                String versionSlug = params.get("versionSlug").getString();
                String docId = params.get("docId").getString();
                // process the file
                TranslationsResource transRes =
                        translationFileServiceImpl.parseTranslationFile(params
                                .get("uploadFileElement").getInputStream(),
                                params.get("fileName").getString(),
                                params.get("targetLocale").getString(),
                                projectSlug, versionSlug, docId);
View Full Code Here

Examples of org.zanata.rest.dto.resource.TranslationsResource

        return parseTranslationFile(rawDoc, filterParams);
    }

    private TranslationsResource parseTranslationFile(RawDocument rawDoc,
            Optional<String> params) {
        TranslationsResource transRes = new TranslationsResource();
        List<TextFlowTarget> translations = transRes.getTextFlowTargets();

        Map<String, HasContents> addedResources =
                new HashMap<String, HasContents>();
        updateParams(params);
        try {
View Full Code Here

Examples of org.zanata.rest.dto.resource.TranslationsResource

    public void uploadTranslationFile(HLocale hLocale) {
        identity.checkPermission("modify-translation", hLocale, getVersion()
                .getProject());
        try {
            // process the file
            TranslationsResource transRes =
                    translationFileServiceImpl.parseTranslationFile(
                            translationFileUpload.getFileContents(),
                            translationFileUpload.getFileName(), hLocale
                                    .getLocaleId().getId(), projectSlug,
                            versionSlug, translationFileUpload.docId);
View Full Code Here

Examples of org.zanata.rest.dto.resource.TranslationsResource

                        Collections.<String>emptySet(), mergeType);
        checkStatusAndReleaseConnection(response);
    }

    public static TranslationsResource buildTranslationResource(TextFlowTarget... targets) {
        TranslationsResource resource = new TranslationsResource();
        resource.setRevision(0);
        resource.getTextFlowTargets().addAll(Lists.newArrayList(targets));
        return resource;
    }
View Full Code Here

Examples of org.zanata.rest.dto.resource.TranslationsResource

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

Examples of org.zanata.rest.dto.resource.TranslationsResource

                                            previousParts,
                                            uploadForm));
                }
            }

            TranslationsResource transRes;
            if (uploadForm.getFileType().equals(".po")) {
                InputStream poStream = getInputStream(tempFile, uploadForm);
                transRes =
                        translationFileServiceImpl.parsePoFile(poStream,
                                id.getProjectSlug(), id.getVersionSlug(),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.