Skip to content

Commit

Permalink
QStar SOAP Client to prefetch/retrieve or fetch file information of …
Browse files Browse the repository at this point in the history
…specified files #1311
  • Loading branch information
gunterze committed May 17, 2023
1 parent 67f175a commit d4ce21b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
2 changes: 2 additions & 0 deletions dcm4che-tool/dcm4che-tool-qstar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Options:
no target directory is specified, the files
will be prefetched to the QStar cache and no
file will be created in the filesystem.
-s,--sort sort specified list of files for retrieve by
its position on the media.
-u,--user <user:password> user name and password to use for server
authentication.
-U,--url <url> request URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@
import javax.xml.ws.BindingProvider;
import java.math.BigInteger;
import java.time.Instant;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.*;

/**
* @author Gunter Zeilinger (gunterze@protonmail.com)
Expand Down Expand Up @@ -124,6 +121,16 @@ public static void main(String[] args) {
List<String> fileList = cl.getArgList();
if (qstar.login(user[0], user[1])) {
if (cl.hasOption("r")) {
if (cl.hasOption("s")) {
SortedSet<FilePosition> filePositions = new TreeSet<>();
for (String filePath : fileList) {
filePositions.add(new FilePosition(filePath, qstar.getFileInfo(filePath)));
}
fileList.clear();
for (FilePosition filePosition : filePositions) {
fileList.add(filePosition.filePath);
}
}
BigInteger jobId = qstar.batchFileRetrieve(
((Number) cl.getParsedOptionValue("r")).longValue(),
fileList,
Expand Down Expand Up @@ -177,6 +184,42 @@ public static void main(String[] args) {
}
}

private static class FilePosition implements Comparable<FilePosition> {
private final String filePath;
private long vol;
private long pos;

public FilePosition(String filePath, WSGetFileInfoResponse fileInfo) {
this.filePath = filePath;
if (fileInfo == null) return;
List<WSFileExtentInfo> extent = fileInfo.getInfo().getFlocExtents().getExtent();
if (extent.isEmpty()) return;
WSFileExtentInfo wsFileExtentInfo = extent.get(0);
this.vol = wsFileExtentInfo.getVol();
this.pos = wsFileExtentInfo.getPos();
}

@Override
public int compareTo(FilePosition o) {
return vol < o.vol ? -1 : vol > o.vol ? 1 : pos < o.pos ? -1 : pos > o.pos ? 1 : 0;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

FilePosition that = (FilePosition) o;

return filePath.equals(that.filePath);
}

@Override
public int hashCode() {
return filePath.hashCode();
}
}

private static CommandLine parseComandLine(String[] args) throws ParseException {
Options opts = new Options();
CLIUtils.addCommonOptions(opts);
Expand Down Expand Up @@ -226,6 +269,10 @@ private static CommandLine parseComandLine(String[] args) throws ParseException
.argName("ms")
.desc(rb.getString("progress"))
.build());
group.addOption(Option.builder("s")
.longOpt("sort")
.desc(rb.getString("sort"))
.build());
opts.addOptionGroup(group);
return CLIUtils.parseComandLine(args, opts, rb, QStar.class);
}
Expand Down Expand Up @@ -261,17 +308,19 @@ private void logout() {
}
}

private void getFileInfo(String filePath) {
private WSGetFileInfoResponse getFileInfo(String filePath) {
try {
WSGetFileInfoRequest rq = factory.createWSGetFileInfoRequest();
rq.setSFileFullPath(filePath);
rq.setUserToken(userLogin.getUserToken());
LOG.info("<< WSGetFileInfoRequest{sFileFullPath='{}', userToken='{}'}", filePath, userLogin.getUserToken());
WSGetFileInfoResponse fileInfo = port.wsGetFileInfo(rq);
LOG.info(">> WSGetFileInfoResponse{status={}, info={}}", fileInfo.getStatus(), toString(fileInfo.getInfo()));
return fileInfo;
} catch (Exception e) {
LOG.info("GetFileInfo Failed: {}", e.getMessage(), e);
}
return null;
}

private BigInteger batchFileRetrieve(long jobPriority, List<String> fileList, String targetDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ progress=continue fetching the retrieve status of specified files in specified i
request until the retrieve job is completed. If no interval is specified, fetch status continuously without delay \
between successive object status requests.
purge=purge specified files from the QStar cache.
sort=sort specified list of files for retrieve by its position on the media.
missing-user-opt=missing required option -u
missing-url-opt=missing required option --url

0 comments on commit d4ce21b

Please sign in to comment.