/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.dicom.model;
import clips.delegate.doctor.checkup.DicomDeviceParamsLocal;
import clips.delegate.doctor.checkup.DicomDeviceParamsSearchLocal;
import clips.dicom.dicombaseclass.DICOMDeviceParam;
import clips.dicom.dicombaseclass.DICOMProtoStore;
import clips.dicom.dicomdataimpl.DICOMServiceOptions;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ConfigGui;
import clips.main.ClipsConfig;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
/**
*
* @author finder
*/
public class ClipsDicomConfigStore implements DICOMProtoStore {
public static final String DUMP_FILE_NAME_BEGIN = "DUMP";
public static final String DUMP_FILE_NAME_END = ".zip";
public static final String DUMP_FILE_NAME_REGEX = "%1$04d";
@Override
public DICOMServiceOptions getConfig() {
return ClipsConfig.getInstance().getDicomService();
}
@Override
public DICOMDeviceParam findDevice(String modelName, String deviceUI, String implementationUID, String implementationVersion, String ipAddres) {
try {
DicomDeviceParamsLocal device
= new DicomDeviceParamsSearchLocal(null).findDevice(modelName, deviceUI, implementationUID, implementationVersion);//NULL AL
if (device != null) {
return device.getParams();
}
else {
return null;
}
} catch (ClipsException ex) {
// nothing more, what i can do here
ex.printStackTrace();
return null;
}
}
static public int parseDumpFileName(String name){
if (name.startsWith(DUMP_FILE_NAME_BEGIN) && name.endsWith(DUMP_FILE_NAME_END)){
String num = name.substring(
DUMP_FILE_NAME_BEGIN.length(),
name.length() - DUMP_FILE_NAME_END.length());
try{
return Integer.parseInt(num);
}
catch (NumberFormatException ex){
// do nothing
return -1;
}
}
else {
return -1;
}
}
@Override
public File getNewDumpFile() throws IOException {
synchronized (ClipsDicomConfigStore.class){
File dir = ClipsConfig.getInstance().getDicomDumpDir();
if (!dir.exists()) {
dir.mkdirs();
}
if (dir.exists() && dir.isDirectory()){
String[] dirFiles = dir.list();
int maxid = 0;
for (String file : dirFiles) {
int curid = parseDumpFileName(file);
maxid = Math.max(maxid, curid);
}
File newFile = new File(dir, DUMP_FILE_NAME_BEGIN + String.format(DUMP_FILE_NAME_REGEX, maxid + 1) + DUMP_FILE_NAME_END);
newFile.createNewFile();
return newFile;
}
else {
return null;
}
}
}
}