Package org.zanata.model

Examples of org.zanata.model.HDocument


            @PathParam("versionSlug") String versionSlug,
            @PathParam("docId") String docId,
            @PathParam("localeId") String localeId) {
        docId = URIHelper.convertFromDocumentURIId(docId);

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

        if (document == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }

        HLocale hLocale = localeServiceImpl.getByLocaleId(localeId);
        if (hLocale == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }

        TextFlowResultTransformer resultTransformer =
                new TextFlowResultTransformer(hLocale);

        FilterConstraints filterConstraints = FilterConstraints.builder().build();

        List<HTextFlow> textFlows =
                textFlowDAO.getNavigationByDocumentId(
                        new DocumentId(document.getId(), document.getDocId()),
                        hLocale, resultTransformer, filterConstraints);

        List<TransUnitStatus> statusList =
                Lists.newArrayListWithExpectedSize(textFlows.size());
View Full Code Here


            @PathParam("docId") String docId,
            @PathParam("localeId") String localeId) {

        docId = URIHelper.convertFromDocumentURIId(docId);

        HDocument doc =
                documentDAO.getByProjectIterationAndDocId(projectSlug,
                        versionSlug, docId);

        if (doc == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }

        ContainerTranslationStatistics docStats =
                getDocStatistics(doc.getId(), new LocaleId(localeId));

        TranslationStatistics docWordStatistic =
                docStats.getStats(localeId, StatUnit.WORD);
        TranslationStatistics docMsgStatistic =
                docStats.getStats(localeId, StatUnit.MESSAGE);
View Full Code Here

                    .status(Response.Status.BAD_REQUEST)
                    .entity("not a legal resource name: " + resourceName)
                    .build());
        }

        HDocument document =
                documentDAO.getByDocIdAndIteration(hProjectIteration,
                        resourceName);

        // already existing non-obsolete document.
        if (document != null) {
            if (!document.isObsolete()) {
                // updates must happen through PUT on the actual resource
                return Response
                        .status(Response.Status.CONFLICT)
                        .entity("A document with name " + resourceName
                                + " already exists.").build();
            }
        }

        // TODO No need for docId param since it's resource.getName()
        document =
                this.documentServiceImpl.saveDocument(this.projectSlug,
                        this.iterationSlug, resource, extensions, copytrans);

        EntityTag etag =
                eTagUtils.generateETagForDocument(hProjectIteration,
                        document.getDocId(), extensions);

        return Response
                .created(
                        URI.create("r/"
                                + resourceUtils.encodeDocId(document.getDocId())))
                .tag(etag).build();
    }
View Full Code Here

        Response.ResponseBuilder response = request.evaluatePreconditions(etag);
        if (response != null) {
            return response.build();
        }

        HDocument doc =
                documentDAO.getByDocIdAndIteration(hProjectIteration, id);

        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

        Response.ResponseBuilder response;
        HProjectIteration hProjectIteration = retrieveAndCheckIteration(true);

        resourceUtils.validateExtensions(extensions);

        HDocument document =
                this.documentDAO.getByDocIdAndIteration(hProjectIteration, id);
        if (document == null || document.isObsolete()) {
            response = Response.created(uri.getAbsolutePath());
        } else {
            response = Response.ok();
        }

        resource.setName(id);
        document =
                this.documentServiceImpl.saveDocument(projectSlug,
                        iterationSlug, resource, extensions, copytrans);

        EntityTag etag =
                eTagUtils.generateETagForDocument(hProjectIteration,
                        document.getDocId(), extensions);

        log.debug("put resource successfully");
        return response.tag(etag).build();
    }
View Full Code Here

        Response.ResponseBuilder response = request.evaluatePreconditions(etag);
        if (response != null) {
            return response.build();
        }

        HDocument document =
                documentDAO.getByDocIdAndIteration(hProjectIteration, id);
        documentServiceImpl.makeObsolete(document);
        return Response.ok().build();
    }
View Full Code Here

        Response.ResponseBuilder response = request.evaluatePreconditions(etag);
        if (response != null) {
            return response.build();
        }

        HDocument doc =
                documentDAO.getByDocIdAndIteration(hProjectIteration, id);

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

        ResourceMeta entity = new ResourceMeta(doc.getDocId());
        resourceUtils.transferToAbstractResourceMeta(doc, entity);

        // transfer extensions
        resourceUtils.transferToResourceExtensions(doc,
                entity.getExtensions(true), extensions);
View Full Code Here

        }

        log.debug("pass evaluation");
        log.debug("put resource meta: {}", messageBody);

        HDocument document =
                documentDAO.getByDocIdAndIteration(hProjectIteration, id);
        if (document == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        if (document.isObsolete()) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        HLocale hLocale =
                validateTargetLocale(messageBody.getLang(), projectSlug,
                        iterationSlug);
        boolean changed =
                resourceUtils.transferFromResourceMetadata(messageBody,
                        document, extensions, hLocale,
                        document.getRevision() + 1);

        if (changed) {
            documentDAO.flush();
            etag =
                    eTagUtils.generateETagForDocument(hProjectIteration, id,
                            extensions);
        }

        log.debug("put resource meta successfully");
        return Response.ok().tag(etag).lastModified(document.getLastChanged())
                .build();

    }
View Full Code Here

        q.setParameter("iterationSlug", iterationSlug)
                .setParameter("projectSlug", projectSlug)
                .setParameter("docId", docId);
        q.setComment("DocumentDAO.getByProjectIterationAndDocId");
        q.setCacheable(true);
        final HDocument doc = (HDocument) q.uniqueResult();
        return doc;
    }
View Full Code Here

    @NativeQuery
    public String
            getTranslatedDocumentStateHash(final String projectSlug,
                    final String iterationSlug, final String docId,
                    final HLocale locale) {
        HDocument doc =
                getByProjectIterationAndDocId(projectSlug, iterationSlug, docId);
        if (doc == null) {
            return "";
        }
        // NB: This method uses a native SQL query tested on mysql and h2
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.