예제 #1
0
  public Process createZanataPushProcess(
      final String baseUrl,
      final Integer contentSpecId,
      final String processName,
      final boolean contentSpecOnly,
      final boolean disableCopyTrans,
      final boolean allowUnfrozenPush,
      final String username,
      final String apikey)
      throws Failure {

    try {
      transaction.begin();
      entityManager.joinTransaction();

      // Load the content spec
      final ContentSpec contentSpec = getContentSpec(contentSpecId);
      final Number revision = EnversUtilities.getLatestRevision(entityManager, contentSpec);

      // Load the zanata details
      final ZanataDetails zanataDetails =
          createZanataDetails(contentSpec.getTranslationDetails(), username, apikey);

      // Fix the process name if one wasn't specified
      final String fixedProcessName =
          "Content Spec Translation Push for "
              + contentSpec.getId()
              + "-"
              + revision.intValue()
              + (isNullOrEmpty(processName) ? "" : (" - " + processName));

      // Create the process
      final Process entity = new Process();
      final PGProcess process = new PGProcess(entity);

      // Set the core fields
      entity.setType(ProcessType.TRANSLATION_PUSH);
      entity.setStartTime(new Date());
      process.setName(fixedProcessName);
      // TODO add user who started the process
      // process.setStartedBy();

      // Add the task
      process.addTask(
          new ZanataPushTask(
              baseUrl,
              contentSpecId,
              contentSpecOnly,
              disableCopyTrans,
              allowUnfrozenPush,
              zanataDetails));

      // Add the process to the content spec
      final ContentSpecToProcess contentSpecToProcess = new ContentSpecToProcess();
      contentSpecToProcess.setProcess(entity);
      contentSpec.addProcess(contentSpecToProcess);

      // Save the newly created process entity and content spec mapping
      entityManager.persist(entity);
      entityManager.persist(contentSpecToProcess);
      entityManager.flush();

      // Start the process
      processManager.startProcess(process);

      transaction.commit();

      return entity;
    } catch (JPPFException e) {
      throw RESTv1Utilities.processError(transaction, new InternalServerErrorException(e));
    } catch (Throwable e) {
      throw RESTv1Utilities.processError(transaction, e);
    }
  }
예제 #2
0
  public Process createZanataSyncProcess(
      final String baseUrl,
      final Integer contentSpecId,
      final String processName,
      final String locales,
      final String username,
      final String apikey)
      throws Failure {

    try {
      transaction.begin();
      entityManager.joinTransaction();

      // Load the content spec to make sure it exists
      final ContentSpec contentSpec = getContentSpec(contentSpecId);

      // Get the translation details
      final ZanataDetails zanataDetails =
          createZanataDetails(contentSpec.getTranslationDetails(), username, apikey);

      // Convert and check the locales
      final Collection<LocaleId> localeList =
          buildLocaleList(contentSpec.getTranslationDetails().getLocales(), locales);

      // Fix the process name if one wasn't specified
      final String fixedProcessName =
          "Content Spec Translation Sync for "
              + contentSpec.getId()
              + (isNullOrEmpty(processName) ? "" : (" - " + processName));

      // Create the process
      final Process entity = new Process();
      final PGProcess process = new PGProcess(entity);

      // Set the core fields
      entity.setType(ProcessType.TRANSLATION_SYNC);
      entity.setStartTime(new Date());
      process.setName(fixedProcessName);
      // TODO add user who started the process
      // process.setStartedBy();

      // Add the task
      process.addTask(new ZanataSyncTask(baseUrl, contentSpecId, localeList, zanataDetails));

      // Add the process to the content spec
      final ContentSpecToProcess contentSpecToProcess = new ContentSpecToProcess();
      contentSpecToProcess.setProcess(entity);
      contentSpec.addProcess(contentSpecToProcess);

      // Save the newly created process entity and content spec mapping
      entityManager.persist(entity);
      entityManager.persist(contentSpecToProcess);
      entityManager.flush();

      // Start the process
      processManager.startProcess(process);

      transaction.commit();

      return entity;
    } catch (JPPFException e) {
      throw RESTv1Utilities.processError(transaction, new InternalServerErrorException(e));
    } catch (Throwable e) {
      throw RESTv1Utilities.processError(transaction, e);
    }
  }