From b985a9222cb3540860cc1199c739addfd3e23789 Mon Sep 17 00:00:00 2001 From: David Mason Date: Tue, 16 Jul 2013 17:10:44 +1000 Subject: [PATCH] make FileService.parsePotFile static (mikado method) --- .../org/zanata/rest/service/FileService.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/zanata-war/src/main/java/org/zanata/rest/service/FileService.java b/zanata-war/src/main/java/org/zanata/rest/service/FileService.java index 626ee70aa8..27d435be68 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/FileService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/FileService.java @@ -218,7 +218,8 @@ private Response tryUploadSourceFile(String projectSlug, String iterationSlug, S if (uploadForm.getFileType().equals(".pot")) { InputStream potStream = getInputStream(tempFile, uploadForm); - parsePotFile(potStream, projectSlug, iterationSlug, docId, uploadForm); + parsePotFile(potStream, projectSlug, iterationSlug, docId, uploadForm, + translationFileServiceImpl, documentServiceImpl, documentDAO); } else { @@ -431,11 +432,6 @@ private static boolean isSinglePart(DocumentFileUploadForm uploadForm) return uploadForm.getFirst() && uploadForm.getLast(); } - private boolean useOfflinePo(String projectSlug, String iterationSlug, String docId) - { - return !isNewDocument(projectSlug, iterationSlug, docId, documentDAO) && !translationFileServiceImpl.isPoDocument(projectSlug, iterationSlug, docId); - } - private static boolean isNewDocument(String projectSlug, String iterationSlug, String docId, DocumentDAO dao) { return dao.getByProjectIterationAndDocId(projectSlug, iterationSlug, docId) == null; @@ -587,20 +583,26 @@ private static void checkUploadPreconditions(String projectSlug, String iteratio } } - private void parsePotFile(InputStream potStream, String projectSlug, String iterationSlug, String docId, DocumentFileUploadForm uploadForm) - { - parsePotFile(potStream, docId, uploadForm.getFileType(), projectSlug, iterationSlug, useOfflinePo(projectSlug, iterationSlug, docId)); - } - - private void parsePotFile(InputStream documentStream, String docId, String fileType, String projectSlug, String iterationSlug, boolean asOfflinePo) + private static void parsePotFile(InputStream potStream, String projectSlug, String iterationSlug, + String docId, DocumentFileUploadForm uploadForm, + TranslationFileService translationFileServiceImpl, + DocumentService documentServiceImpl, + DocumentDAO documentDAO) { Resource doc; - doc = translationFileServiceImpl.parseUpdatedPotFile(documentStream, docId, fileType, asOfflinePo); + doc = translationFileServiceImpl.parseUpdatedPotFile(potStream, docId, uploadForm.getFileType(), + useOfflinePo(projectSlug, iterationSlug, docId, documentDAO, translationFileServiceImpl)); doc.setLang( new LocaleId("en-US") ); // TODO Copy Trans values documentServiceImpl.saveDocument(projectSlug, iterationSlug, doc, new StringSet(ExtensionType.GetText.toString()), false); } + private static boolean useOfflinePo(String projectSlug, String iterationSlug, String docId, + DocumentDAO documentDAO, TranslationFileService translationFileServiceImpl) + { + return !isNewDocument(projectSlug, iterationSlug, docId, documentDAO) && !translationFileServiceImpl.isPoDocument(projectSlug, iterationSlug, docId); + } + private static Response sourceUploadSuccessResponse(boolean isNewDocument, int acceptedChunks) { Response response;