コード例 #1
0
  @Override
  public GetDocumentListResult execute(GetDocumentList action, ExecutionContext context)
      throws ActionException {
    identity.checkLoggedIn();

    LocaleId localeId = action.getWorkspaceId().getLocaleId();
    ProjectIterationId iterationId = action.getProjectIterationId();
    ArrayList<DocumentInfo> docs = new ArrayList<DocumentInfo>();
    HProjectIteration hProjectIteration =
        projectIterationDAO.getBySlug(iterationId.getProjectSlug(), iterationId.getIterationSlug());
    Collection<HDocument> hDocs = hProjectIteration.getDocuments().values();
    for (HDocument hDoc : hDocs) {
      if (action.getFilters() == null
          || action.getFilters().isEmpty()
          || action.getFilters().contains(hDoc.getPath() + hDoc.getName())) {
        DocumentId docId = new DocumentId(hDoc.getId(), hDoc.getDocId());
        TranslationStats stats = documentDAO.getStatistics(hDoc.getId(), localeId);
        String lastModifiedBy = "";
        HPerson person = hDoc.getLastModifiedBy();
        if (person != null) {
          lastModifiedBy = person.getAccount().getUsername();
        }

        Map<String, String> downloadExtensions = new HashMap<String, String>();
        downloadExtensions.put(".po", "po?docId=" + hDoc.getDocId());
        if (translationFileServiceImpl.hasPersistedDocument(
            iterationId.getProjectSlug(),
            iterationId.getIterationSlug(),
            hDoc.getPath(),
            hDoc.getName())) {
          String extension =
              "."
                  + translationFileServiceImpl.getFileExtension(
                      iterationId.getProjectSlug(),
                      iterationId.getIterationSlug(),
                      hDoc.getPath(),
                      hDoc.getName());
          downloadExtensions.put(extension, "baked?docId=" + hDoc.getDocId());
        }

        DocumentInfo doc =
            new DocumentInfo(
                docId,
                hDoc.getName(),
                hDoc.getPath(),
                hDoc.getLocale().getLocaleId(),
                stats,
                lastModifiedBy,
                hDoc.getLastChanged(),
                downloadExtensions);
        docs.add(doc);
      }
    }
    return new GetDocumentListResult(iterationId, docs);
  }
コード例 #2
0
  @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 |=
        resourceUtils.transferFromResource(sourceDoc, document, extensions, hLocale, nextDocRev);
    documentDAO.flush();

    long actorId = authenticatedAccount.getPerson().getId();
    if (changed) {
      documentUploadedEvent.fireAfterSuccess(
          new DocumentUploadedEvent(actorId, document.getId(), true, hLocale.getLocaleId()));
      clearStatsCacheForUpdatedDocument(document);
    }

    if (copyTrans && nextDocRev == 1) {
      copyTranslations(document);
    }

    return document;
  }
コード例 #3
0
  private void prepareTransUnitUpdatedEvent(
      int previousVersionNum, ContentState previousState, HTextFlowTarget target) {
    LocaleId localeId = target.getLocaleId();
    HTextFlow textFlow = target.getTextFlow();
    HDocument document = textFlow.getDocument();
    HProjectIteration projectIteration = document.getProjectIteration();
    String iterationSlug = projectIteration.getSlug();
    String projectSlug = projectIteration.getProject().getSlug();
    ProjectType projectType = projectIteration.getProjectType();

    WorkspaceId workspaceId =
        new WorkspaceId(new ProjectIterationId(projectSlug, iterationSlug, projectType), localeId);
    Optional<TranslationWorkspace> workspaceOptional =
        translationWorkspaceManager.tryGetWorkspace(workspaceId);
    if (!workspaceOptional.isPresent()) {
      return;
    }

    TransUnitTransformer transUnitTransformer =
        serviceLocator.getInstance(TransUnitTransformer.class);
    TransUnit transUnit = transUnitTransformer.transform(textFlow, target, target.getLocale());

    DocumentId documentId = new DocumentId(document.getId(), document.getDocId());
    int wordCount = textFlow.getWordCount().intValue();

    TransUnitUpdateInfo updateInfo =
        createTransUnitUpdateInfo(
            transUnit, documentId, wordCount, previousVersionNum, previousState);

    CacheValue context =
        updateContext.getIfPresent(new CacheKey(transUnit.getId(), transUnit.getLocaleId()));
    TransUnitUpdated updated;
    if (context != null) {
      updated = new TransUnitUpdated(updateInfo, context.editorClientId, context.updateType);
      log.debug("about to publish trans unit updated event {}", updated);
    } else if (ServletContexts.instance().getRequest() != null) {

      String sessionId = ServletContexts.instance().getRequest().getSession().getId();
      EditorClientId editorClientId = new EditorClientId(sessionId, -1);
      updated =
          new TransUnitUpdated(
              updateInfo, editorClientId, TransUnitUpdated.UpdateType.NonEditorSave);
    } else {
      updated =
          new TransUnitUpdated(
              updateInfo,
              new EditorClientId("unknown", -1),
              TransUnitUpdated.UpdateType.NonEditorSave);
    }
    if (Events.exists()) {
      Events.instance()
          .raiseTransactionSuccessEvent(
              TextFlowTargetUpdatedEvent.EVENT_NAME,
              new TextFlowTargetUpdatedEvent(workspaceOptional.get(), target.getId(), updated));
    }
  }
コード例 #4
0
  @Override
  public GetDocumentListResult execute(GetDocumentList action, ExecutionContext context)
      throws ActionException {

    ZanataIdentity.instance().checkLoggedIn();

    ProjectIterationId iterationId = action.getProjectIterationId();
    ArrayList<DocumentInfo> docs = new ArrayList<DocumentInfo>();
    HProjectIteration hProjectIteration =
        projectIterationDAO.getBySlug(iterationId.getProjectSlug(), iterationId.getIterationSlug());
    Collection<HDocument> hDocs = hProjectIteration.getDocuments().values();
    for (HDocument hDoc : hDocs) {
      DocumentId docId = new DocumentId(hDoc.getId());
      DocumentInfo doc = new DocumentInfo(docId, hDoc.getName(), hDoc.getPath());
      docs.add(doc);
    }
    return new GetDocumentListResult(iterationId, docs);
  }
コード例 #5
0
  private void signalCopiedTranslation(
      HTextFlowTarget target, ContentState previousState, Long wordCount) {
    /*
     * Using a direct method call instead of an event because it's easier to
     * read. Since these events are being called synchronously (as opposed
     * to an 'after Transaction' events), there is no big performance gain
     * and makes the code easier to read and navigate.
     */
    // TODO how was this not causing duplicate events?  Is this bypassing TranslationServiceImpl?
    // FIXME other observers may not be notified
    HDocument document = target.getTextFlow().getDocument();

    DocumentLocaleKey key = new DocumentLocaleKey(document.getId(), target.getLocaleId());

    Map<ContentState, Long> contentStates = Maps.newHashMap();
    DocStatsEvent.updateContentStateDeltas(
        contentStates, target.getState(), previousState, wordCount);

    DocStatsEvent docEvent =
        new DocStatsEvent(
            key, document.getProjectIteration().getId(), contentStates, target.getId());

    versionStateCacheImpl.docStatsUpdated(docEvent);
  }
コード例 #6
0
 private void clearStatsCacheForUpdatedDocument(HDocument document) {
   versionStateCacheImpl.clearVersionStatsCache(document.getProjectIteration().getId());
   translationStateCacheImpl.clearDocumentStatistics(document.getId());
 }
コード例 #7
0
  @Override
  public ContainerTranslationStatistics getStatistics(
      String projectSlug,
      String iterationSlug,
      String docId,
      boolean includeWordStats,
      String[] locales) {
    LocaleId[] localeIds;

    // if no locales are specified, search in all locales
    if (locales.length == 0) {
      List<HLocale> iterationLocales =
          localeServiceImpl.getSupportedLangugeByProjectIteration(projectSlug, iterationSlug);
      localeIds = new LocaleId[iterationLocales.size()];
      for (int i = 0, iterationLocalesSize = iterationLocales.size();
          i < iterationLocalesSize;
          i++) {
        HLocale loc = iterationLocales.get(i);
        localeIds[i] = loc.getLocaleId();
      }
    } else {
      localeIds = new LocaleId[locales.length];
      for (int i = 0; i < locales.length; i++) {
        localeIds[i] = new LocaleId(locales[i]);
      }
    }

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

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

    ContainerTranslationStatistics docStatistics = new ContainerTranslationStatistics();
    docStatistics.setId(docId);
    docStatistics.addRef(
        new Link(URI.create(zPathService.generatePathForDocument(document)), "statSource", "DOC"));

    for (LocaleId localeId : localeIds) {
      ContainerTranslationStatistics docStats = getDocStatistics(document.getId(), localeId);

      DocumentStatus docStatus =
          translationStateCacheImpl.getDocumentStatus(document.getId(), localeId);

      TranslationStatistics docWordStatistic = docStats.getStats(localeId.getId(), StatUnit.WORD);
      TranslationStatistics docMsgStatistic = docStats.getStats(localeId.getId(), StatUnit.MESSAGE);

      docMsgStatistic.setLastTranslatedBy(docStatus.getLastTranslatedBy());
      docMsgStatistic.setLastTranslatedDate(docStatus.getLastTranslatedDate());
      docMsgStatistic.setLastTranslated(
          getLastTranslated(docStatus.getLastTranslatedDate(), docStatus.getLastTranslatedBy()));
      docStatistics.addStats(docMsgStatistic);

      if (includeWordStats) {
        docWordStatistic.setLastTranslatedBy(docStatus.getLastTranslatedBy());
        docWordStatistic.setLastTranslatedDate(docStatus.getLastTranslatedDate());
        docWordStatistic.setLastTranslated(
            getLastTranslated(docStatus.getLastTranslatedDate(), docStatus.getLastTranslatedBy()));
        docStatistics.addStats(docWordStatistic);
      }
    }
    return docStatistics;
  }