Package org.zanata.rest.dto.resource

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


      final Status status = Response.Status.fromStatusCode(response.getStatus());
     
      if (status == Response.Status.OK)
      {
        final Resource entity = response.getEntity();
        return entity;
      }
      else
      {
        System.out.println("REST call to getResource() did not complete successfully. HTTP response code was " + status.getStatusCode() + ". Reason was " + status.getReasonPhrase());
View Full Code Here


      final IFixedTranslationResources client = ProxyFactory.create(IFixedTranslationResources.class, URI);
      final ClientResponse<Resource> response = client.getResource("test");

      if (response.getStatus() == 200)
      {
        final Resource entity = response.getEntity();
        System.out.println(entity.getName());

        for (final TextFlow textFlow : entity.getTextFlows())
          System.out.println(textFlow.getContent());
      }
      else
      {
        System.out.println("Return code: " + response.getStatus());
View Full Code Here

      final String server = "http://zanata-fortitude.lab.eng.bne.redhat.com:8080";
      final String project = "demo";
      final String version = "1.0";
      final String URI = server + "/seam/resource/restv1/projects/p/" + project + "/iterations/i/" + version + "/r";

      final Resource resource = new Resource();
      resource.setLang(LocaleId.EN_US);
      resource.setName("test");
      resource.setRevision(1);
      resource.setType(ResourceType.FILE);

      final TextFlow textFlow = new TextFlow();
      textFlow.setId("id");
      textFlow.setContent("Some text to be translated");
      textFlow.setLang(LocaleId.EN_US);
      textFlow.setRevision(1);

      resource.getTextFlows().add(textFlow);

      /* create a http client to supply the credentials */
      final HttpClient httpClient = new HttpClient();
      final ApacheHttpClientExecutor executor = new ApacheHttpClientExecutor(httpClient)
      {
View Full Code Here

        if (doc == null || doc.isObsolete()) {
            return Response.status(Response.Status.NOT_FOUND)
                    .entity("document not found").build();
        }

        Resource entity = new Resource(doc.getDocId());
        log.debug("get resource details {}", entity.toString());
        resourceUtils.transferToResource(doc, entity);

        for (HTextFlow htf : doc.getTextFlows()) {
            TextFlow tf =
                    new TextFlow(htf.getResId(), doc.getLocale().getLocaleId());
            resourceUtils.transferToTextFlow(htf, tf);
            resourceUtils.transferToTextFlowExtensions(htf,
                    tf.getExtensions(true), extensions);
            entity.getTextFlows().add(tf);
        }

        // handle extensions
        resourceUtils.transferToResourceExtensions(doc,
                entity.getExtensions(true), extensions);
        log.debug("Get resource :{}", entity.toString());
        return Response.ok().entity(entity).tag(etag)
                .lastModified(doc.getLastChanged()).build();
    }
View Full Code Here

        // null documentContent is handled by RawDocument constructor
        if (sourceLocale == null) {
            throw new IllegalArgumentException("Source locale cannot be null");
        }

        Resource document = new Resource();
        document.setLang(sourceLocale);
        document.setContentType(ContentType.TextPlain);

        List<TextFlow> resources = document.getTextFlows();
        Map<String, HasContents> addedResources =
                new HashMap<String, HasContents>();

        RawDocument rawDoc =
                new RawDocument(documentContent, "UTF-8",
View Full Code Here

                        versionSlug, docId);
        boolean docExists = existingDoc != null;
        boolean useOfflinePo = docExists && !isPoDocument(docId);

        try {
            Resource doc =
                    translationFileServiceImpl.parseUpdatedPotFile(
                            sourceFileUpload.getFileContents(), docId,
                            sourceFileUpload.getFileName(), useOfflinePo);

            doc.setLang(new LocaleId(sourceFileUpload.getSourceLang()));

            // TODO Copy Trans values
            documentServiceImpl.saveDocument(projectSlug, versionSlug, doc,
                    new StringSet(ExtensionType.GetText.toString()), false);
View Full Code Here

            return;
        }

        HDocument document = null;
        try {
            Resource doc;
            if (docId == null) {
                doc =
                        translationFileServiceImpl.parseAdapterDocumentFile(
                                tempFile.toURI(), documentPath, fileName,
                                getOptionalParams());
            } else {
                doc =
                        translationFileServiceImpl
                                .parseUpdatedAdapterDocumentFile(
                                        tempFile.toURI(), docId, fileName,
                                        getOptionalParams());
            }
            doc.setLang(new LocaleId(sourceFileUpload.getSourceLang()));
            Set<String> extensions = Collections.<String> emptySet();
            // TODO Copy Trans values
            document =
                    documentServiceImpl.saveDocument(projectSlug, versionSlug,
                            doc, extensions, false);
View Full Code Here

    public Resource buildResource(HDocument document) {
        Set<String> extensions = new HashSet<String>();
        extensions.add("gettext");
        extensions.add("comment");

        Resource entity = new Resource(document.getDocId());
        this.transferToResource(document, entity);
        // handle extensions
        this.transferToResourceExtensions(document, entity.getExtensions(true),
                extensions);

        for (HTextFlow htf : document.getTextFlows()) {
            TextFlow tf =
                    new TextFlow(htf.getResId(), document.getLocale()
                            .getLocaleId());
            this.transferToTextFlowExtensions(htf, tf.getExtensions(true),
                    extensions);
            this.transferToTextFlow(htf, tf);
            entity.getTextFlows().add(tf);
        }

        return entity;
    }
View Full Code Here

        return response.getStatus();
    }

    public static Resource buildSourceResource(String name,
            TextFlow... textFlows) {
        Resource resource = new Resource(name);
        resource.setRevision(0);
        resource.getTextFlows().addAll(Lists.newArrayList(textFlows));
        return resource;
    }
View Full Code Here

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

TOP

Related Classes of org.zanata.rest.dto.resource.Resource

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.