From d44924d00be98be9e3a3301f16629316e70a120c Mon Sep 17 00:00:00 2001 From: gexce Date: Thu, 9 Nov 2017 09:17:00 +0100 Subject: [PATCH] forgot non-zipped master files --- .../resources/application.properties | 2 +- .../edam/migration/MamMigrationSelective.java | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/AH MAM Migration/resources/application.properties b/AH MAM Migration/resources/application.properties index e783bf8..4c2d873 100644 --- a/AH MAM Migration/resources/application.properties +++ b/AH MAM Migration/resources/application.properties @@ -2,4 +2,4 @@ logging.level.com.bayer=DEBUG #logging.level.com.bayer.edam.migration.interceptors=INFO logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level- %msg%n -logging.file=application-WED.log +logging.file=application-THU.log diff --git a/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java b/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java index 1a72910..224bdc7 100644 --- a/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java +++ b/AH MAM Migration/src/com/bayer/edam/migration/MamMigrationSelective.java @@ -65,7 +65,7 @@ public class MamMigrationSelective implements CommandLineRunner { private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class); static final String mamHost = "https://service.media-assistant.animalhealth.bayer.com"; - private List entrySelection = new ArrayList(Arrays.asList( 71725, 71263, 71048, 70778, 70746, 70745, 70440, 70361, 70340, 70288, 70161, 70142, 63924, 63201, 57641, 56942 )); + private List entrySelection = new ArrayList(Arrays.asList( 71725 /*, 71263, 71048, 70778, 70746, 70745, 70440, 70361, 70340, 70288, 70161, 70142, 63924, 63201, 57641, 56942 */)); static final String fileCache = "E:\\"; @@ -78,7 +78,7 @@ public class MamMigrationSelective implements CommandLineRunner { @Value("${adam.auth}") private String adamAuth; - RestTemplate restTemplate; + RestTemplate restTemplate, fileTransferTemplate; HttpHeaders adamHeaders, adamUploadHeaders, mamHeaders; HttpEntity adamHeadersEntity; @@ -104,6 +104,11 @@ public class MamMigrationSelective implements CommandLineRunner { log.info("Read categories"); mamCategoryTree = new CategoryTree(categoryJson, categoryMapping); + // XXX + SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); + requestFactory.setBufferRequestBody(false); + fileTransferTemplate = new RestTemplate(requestFactory); + restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); List interceptors = new ArrayList(); interceptors.add(new LoggingRequestInterceptor()); @@ -255,7 +260,14 @@ public class MamMigrationSelective implements CommandLineRunner { // Brands "General" and "Others" are weaker than the other brands if (p.startsWith("Brand.")) { - if ((p.equals("Brand.General") || p.equals("Brand.CAP.Others") || p.equals("Brand.FAP.Others"))&& record.hasClassificationStartingWith("Brand.")) { + if ((p.equals("Brand.General") || p.equals("Brand.CAP.Others") || p.equals("Brand.FAP.Others")) + && record.hasClassificationStartingWith("Brand.")) { + + // Check if the brand matches the business unit XXX +// if ((p.equals("Brand.General") && record.hasClassificationStartingWith("BusinessUnit.General")) || +// (p.equals("Brand.CAP.Others") && record.hasClassificationStartingWith("BusinessUnit.CAP")) || +// (p.equals("Brand.FAP.Others") && record.hasClassificationStartingWith("BusinessUnit.FAP"))) + log.warn("Classification " + p + " not added, different brand already set"); continue; } @@ -510,10 +522,10 @@ public class MamMigrationSelective implements CommandLineRunner { if (selectedDownload != null) { + File masterFile = getFileForEntry(selectedDownload, entry.id); + // if selected download is a zip that contains a single file, upload extracted file as master if (selectedDownload.fileName.toLowerCase().endsWith(".zip")) { - File masterFile = getFileForEntry(selectedDownload, entry.id); - ZipFile zipFile = new ZipFile(masterFile); @SuppressWarnings("unchecked") List fileHeaders = zipFile.getFileHeaders(); @@ -528,10 +540,12 @@ public class MamMigrationSelective implements CommandLineRunner { log.info("Using extracted master file " + extractedMasterFilePath); masterFile = new File(extractedMasterFilePath); } - - filesForUpload.add(masterFile); - hrefsForUpload.add(selectedDownload.href); } + + // XXX E:\71725 wieder herstellen + + filesForUpload.add(masterFile); + hrefsForUpload.add(selectedDownload.href); } else { log.warn("Could not identify master file for entry " + entry.id); @@ -553,7 +567,7 @@ public class MamMigrationSelective implements CommandLineRunner { MultiValueMap parameters = new LinkedMultiValueMap(); parameters.add("file", new FileSystemResource(file)); - UploadResult result = restTemplate.exchange(Definitions.adamHost + "/uploads", HttpMethod.POST, + UploadResult result = fileTransferTemplate.exchange(Definitions.adamHost + "/uploads", HttpMethod.POST, new HttpEntity>(parameters, adamUploadHeaders), UploadResult.class).getBody(); if (result.token != null) {