Skip to content

Commit 53d0dc7

Browse files
committed
Zip downloaded algorithms automatically
1 parent b813563 commit 53d0dc7

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

src/test/java/com/imsweb/staging/cs/CsUpdateFromAPI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.imsweb.staging.cs;
22

33
import java.io.IOException;
4+
import java.nio.file.Paths;
45
import java.util.Collections;
56
import java.util.HashSet;
67

@@ -12,7 +13,7 @@
1213
public class CsUpdateFromAPI {
1314

1415
public static void main(String[] args) throws IOException {
15-
UpdaterUtils.update("cs", "02.05.50", new HashSet<>(Collections.singletonList("STAGING")));
16+
UpdaterUtils.update("cs", "02.05.50", new HashSet<>(Collections.singletonList("STAGING")), Paths.get("c:/dev/tmp"));
1617
}
1718

1819
}

src/test/java/com/imsweb/staging/pediatric/PediatricUpdateFromAPI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.imsweb.staging.pediatric;
22

33
import java.io.IOException;
4+
import java.nio.file.Paths;
45
import java.util.Collections;
56
import java.util.HashSet;
67

@@ -12,7 +13,7 @@
1213
public class PediatricUpdateFromAPI {
1314

1415
public static void main(String[] args) throws IOException {
15-
UpdaterUtils.update("pediatric", "1.3", new HashSet<>(Collections.singletonList("STAGING")));
16+
UpdaterUtils.update("pediatric", "1.3", new HashSet<>(Collections.singletonList("STAGING")), Paths.get("c:/dev/tmp"));
1617
}
1718

1819
}

src/test/java/com/imsweb/staging/tnm/TnmUpdateFromAPI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.imsweb.staging.tnm;
22

33
import java.io.IOException;
4+
import java.nio.file.Paths;
45
import java.util.Collections;
56
import java.util.HashSet;
67

@@ -12,7 +13,7 @@
1213
public class TnmUpdateFromAPI {
1314

1415
public static void main(String[] args) throws IOException {
15-
UpdaterUtils.update("tnm", "2.0", new HashSet<>(Collections.singletonList("STAGING")));
16+
UpdaterUtils.update("tnm", "2.0", new HashSet<>(Collections.singletonList("STAGING")), Paths.get("c:/dev/tmp"));
1617
}
1718

1819
}

src/test/java/com/imsweb/staging/updater/UpdaterUtils.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.io.UncheckedIOException;
56
import java.nio.charset.StandardCharsets;
67
import java.nio.file.Files;
78
import java.nio.file.Path;
@@ -16,6 +17,9 @@
1617
import java.util.Set;
1718
import java.util.regex.Pattern;
1819
import java.util.stream.Collectors;
20+
import java.util.stream.Stream;
21+
import java.util.zip.ZipEntry;
22+
import java.util.zip.ZipOutputStream;
1923

2024
import org.slf4j.Logger;
2125
import org.slf4j.LoggerFactory;
@@ -202,6 +206,15 @@ else if (unusedTableIds.contains(id) && !id.startsWith("conversion_"))
202206
Files.write(Paths.get(glossaryDir + "/terms.txt"), keywords, StandardCharsets.UTF_8);
203207
_LOG.info("Saved glossary terms to {}/terms.txt", schemaDir);
204208

209+
// Zip up schemas/, tables/, glossary/
210+
Path versionDir = Paths.get(baseDirectory);
211+
zipAlgorithm(algorithm, version, versionDir);
212+
213+
_LOG.info("Created ZIP: {}/{}-{}.zip",
214+
versionDir.getParent().getParent(),
215+
algorithm,
216+
version);
217+
205218
stopwatch.stop();
206219
_LOG.info("Completed in {}", stopwatch);
207220
}
@@ -230,4 +243,36 @@ private static int purgeDirectory(File dir) {
230243
return count;
231244
}
232245

246+
/**
247+
* Zip the algorithm
248+
*/
249+
private static void zipAlgorithm(String algorithm, String version, Path versionDir) throws IOException {
250+
Path algorithmsDir = versionDir.getParent().getParent(); // .../algorithms
251+
Path zipPath = algorithmsDir.resolve(algorithm + "-" + version + ".zip");
252+
253+
try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(zipPath))) {
254+
for (String folder : new String[] {"schemas", "tables", "glossary"}) {
255+
Path folderPath = versionDir.resolve(folder);
256+
if (!Files.exists(folderPath))
257+
continue;
258+
259+
try (Stream<Path> walk = Files.walk(folderPath)) {
260+
walk.filter(Files::isRegularFile)
261+
.forEach(path -> {
262+
Path relative = versionDir.relativize(path);
263+
ZipEntry entry = new ZipEntry(relative.toString().replace('\\', '/'));
264+
try {
265+
zos.putNextEntry(entry);
266+
Files.copy(path, zos);
267+
zos.closeEntry();
268+
}
269+
catch (IOException e) {
270+
throw new UncheckedIOException(e);
271+
}
272+
});
273+
}
274+
}
275+
}
276+
}
277+
233278
}

0 commit comments

Comments
 (0)