Skip to content

Commit

Permalink
Fixes for gui and more
Browse files Browse the repository at this point in the history
  • Loading branch information
BobHanson committed Dec 13, 2024
1 parent 0303e7a commit 9b3eb3f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ protected void setDerivedFlags() {
// _IFD_collection.zip file
createZippedCollection = createZippedCollection && !insitu && !debugReadOnly;

cleanCollectionDir &= !insitu;
readOnly |= debugReadOnly; // for testing; when true, no output other than a log file is produced
noOutput = (createFindingAidOnly || readOnly);
skipPubInfo = !dataciteUp || debugReadOnly; // true to allow no internet connection and so no pub calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,23 @@ abstract class IFDExtractorLayer2 extends IFDExtractorLayer1 {
*/
private Map<String, IFDRepresentableObject<?>> htLocalizedNameToObject = new LinkedHashMap<>();

/**
* retrieves a clone data source or a cloned object from an id
*/
private Map<String, IFDRepresentableObject<?>> htCloneMap = new HashMap<>();

/**
* a list of properties that vendors have indicated need addition, keyed by the
* zip path for the resource
*/
private List<Object[]> deferredPropertyList;

/**
* an insertion pointer into the deferredPropertyList;
* reset to 0 after Phase 2b.
*/
private int deferredPropertyPointer;

/**
* a key for the deferredObjectList that indicates we have a new resource
* setting
Expand Down Expand Up @@ -316,6 +327,7 @@ protected void processPhase2(File targetDir) throws IFDException, IOException {
// removing resources that are totally unnecessary and extracting properties
// and representations using IFDVendorPluginI services.

deferredPropertyPointer = 0;
if (rezipCache != null && rezipCache.size() > 0) {
phase2cGetNextRezipName();
lastRezipPath = null;
Expand Down Expand Up @@ -506,6 +518,8 @@ private Map<String, ArchiveEntry> phase2ReadZipContentsIteratively(InputStream i
phase2aProcessEntry(baseOriginPath, oPath, ais, zipEntry, accepted);
break;
case PHASE_2C:


// rezipping
if (oPath.equals(currentRezipPath)) {
// nextRealEntry here may be the first
Expand Down Expand Up @@ -1049,7 +1063,7 @@ private ArchiveEntry phase2cRezipEntry(String baseName, String oPath, ArchiveInp
IFDRepresentation r = faHelper.getSpecDataRepresentation(localizedName);
if (r == null) {
// probably the case, as this renamed representation has not been added yet.
} else {
} else if (!insitu){
r.setLength(len);
}
if (oPath.endsWith(".zip"))
Expand Down Expand Up @@ -1433,7 +1447,14 @@ private static String phase2dGetStructureNameFromPath(String originPath) {
return name;
}

/**
* Get the clone source
* @param spec
* @return
*/
private IFDRepresentableObject<?> phase2dGetClonedData(IFDRepresentableObject<?> spec) {
if (htCloneMap.isEmpty())
return spec;
IFDRepresentableObject<?> d = (spec.isValid() ? null : htCloneMap.get(spec.getID()));
return (d == null ? spec : d);
}
Expand Down Expand Up @@ -1507,13 +1528,13 @@ public void addProperty(String key, Object val) {
public void addDeferredPropertyOrRepresentation(String key, Object val, boolean isInline, String mediaType,
String note, String method) {

// System.out.println("L2 adddef >>>" +key + " src=" + method + " " + val);
//System.out.println("L2 adddef >>>" +key + " src=" + method + " " + val);
if (key == null) {
deferredPropertyList.add(null);
deferredPropertyList.add(deferredPropertyPointer++, null);
return;
}
deferredPropertyList
.add(new Object[] { originPath, localizedName, key, val, Boolean.valueOf(isInline), mediaType, note, method });
.add(deferredPropertyPointer++, new Object[] { originPath, localizedName, key, val, Boolean.valueOf(isInline), mediaType, note, method });
if (key.startsWith(DefaultStructureHelper.STRUC_FILE_DATA_KEY)) {
// Phase 2a has identified a structure before a compound has been established in Phase 2b.
// Mestrelab vendor plug-in has found a MOL or SDF file in Phase 2b.
Expand All @@ -1533,7 +1554,6 @@ public void addDeferredPropertyOrRepresentation(String key, Object val, boolean
}
}

private Map<String, IFDRepresentableObject<?>> htCloneMap = new HashMap<>();

/**
* Register a digital item as significant and to be included in the collection.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// ${IUPAC FAIRSpec}/src/html/site/assets/FAIRSpec-gui.js
//
// Bob Hanson hansonr@stolaf.edu 2024.12.12

// anonymous function for local functions
// Bob Hanson hansonr@stolaf.edu 2024.12.13

;(function() {

Expand Down Expand Up @@ -300,6 +298,7 @@
}

var loadMainSummary = function(aid, isAll) {
clearPDFCache();
var s;
if (isAll && IFD.mainText) {
s = IFD.mainText;
Expand Down Expand Up @@ -520,8 +519,8 @@
s += "<td>&nbsp;&nbsp;</td><td><b>" + title + "</b></td>"
s += "</tr></table>";
var smiles = IFD.getSmilesForStructureID(aidID, structureIDs[0]);
s += showCompoundSpectra(aidID,[id],smiles,false, isAll);
s += showCompoundStructures(aidID,structureIDs, false);
s += showCompoundSpectra(aidID,[id],smiles,false, isAll);
s += "<hr style='color:blue'>";
return s;
}
Expand Down Expand Up @@ -706,12 +705,13 @@
}

var addRepresentationTable = function(isData, aidID, reps, specialItem, isAll) {
var justImage = (!isData && IFD.resultsMode == IFD.MODE_SPECTRA);
var s = ""
for (var i = 0; i < reps.length; i++) {
var type = IFD.shortType(reps[i].representationType);
if (type == specialItem) {
s = addRepresentationRow(isData, aidID, reps[i], type) + s;
} else if ("!" + type != specialItem) {
} else if (!justImage && "!" + type != specialItem) {
s += addRepresentationRow(isData, aidID, reps[i], type);
}
}
Expand Down Expand Up @@ -755,12 +755,30 @@

IFD.showHead = function(i) {alert(heads[i])}

var clearPDFCache = function() {
IFD.pdfData = [];
IFD.pdfDataPt = 0;
}

clearPDFCache();

var anchorBase64 = function(label, sdata, mediaType) {
mediaType || (mediaType = "application/octet-stream");
var s = "<a href=\"data:" + mediaType + sdata + "\")>" + label + "</a>";
if (mediaType.indexOf("/pdf") < 0)
return s;
return "<object data=\"data:application/pdf" + sdata + "\" type=\"application/pdf\" width=\"800\" height=\"600\">" + s +"</object>";
if (mediaType.indexOf("/pdf") >= 0) {
s += getPDFLink("data:application/pdf" + sdata);
}
return s;
}

var getPDFLink = function(uri) {
var s = "&nbsp;&nbsp;<span id=pdf" + IFD.pdfDataPt + "><a href=\"javascript:IFD.viewPDF("+IFD.pdfDataPt+")\">VIEW</a></div>";
IFD.pdfData[IFD.pdfDataPt++] = "<object data=\"" + uri + "\" type=\"application/pdf\" width=\"800\" height=\"600\"></object>";
return s;
}

IFD.viewPDF = function(i) {
$("#pdf" + i).html(IFD.pdfData[i]);
}

var getSpectrumPrediction = function(props, smiles) {
Expand Down Expand Up @@ -871,7 +889,7 @@
url = "data:application/octet-stream" + url;
s = "<a target=_blank href=\"" + url + "\">" + shortName + "</a>" + " (" + getSizeString(len) + (mediaType ? " " + mediaType : "") + ")";
if (IFD.resultsMode == IFD.MODE_SPECTRA && shortName.endsWith(".pdf")) {
s = "<object data=\"" + url + "\" type=\"application/pdf\" width=\"800\" height=\"600\">" + s +"</object>";
s += getPDFLink(url);
}
}
note = (note && note.startsWith("Warning") ? note : null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ private String setOrigin(String val) {
"Temperature", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_ABSOLUTE_TEMPERATURE"), //prop
"DIM", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_DIMENSION"), //prop
"TITLE", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_TITLE"), //prop
"F1", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_FREQ_1"), //prop
"F2", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_FREQ_2"), //prop
"F3", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_FREQ_3"), //prop
"N1", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_NUCL_1"), //prop
"N2", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_NUCL_2"), //prop
"N3", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_NUCL_3"), //prop
"Spectrometer Frequency", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_FREQ_1"), //prop
"Spectrometer Frequency2", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_FREQ_2"), //prop
"Spectrometer Frequency3", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_FREQ_3"), //prop
"Nucleus", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_NUCL_1"), //prop
"Nucleus2", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_NUCL_2"), //prop
"Nucleus3", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.EXPT_NUCL_3"), //prop
"SF", getProp("IFD_PROPERTY_DATAOBJECT_FAIRSPEC_NMR.INSTR_NOMINAL_FREQ"), //prop
"TIMESTAMP", IFDConst.IFD_PROPERTY_DATAOBJECT_TIMESTAMP, //prop
};
Expand Down Expand Up @@ -190,15 +190,16 @@ void addParam(String key, Object oval, Param param1, Param param2) {
case "Site":
case "Solvent":
case "Title":
case "Instrument":
case "Spectrometer":
default:
oval = FAIRSpecUtilities.rep(val, "\n", " ").trim();
break;
case "Purity":
break;
case "Data File Name":
pageGlobals.isJDF = (val.endsWith(".jdf"));
return;
case "Instrument":
case "Spectrometer":
break;
case "Temperature":
double d = Double.parseDouble(val);
if (pageGlobals.isJDF) {
Expand All @@ -208,19 +209,16 @@ void addParam(String key, Object oval, Param param1, Param param2) {
oval = Double.valueOf(d);
break;
case "Nucleus":
key = "N1";
pageGlobals.nuc1 = val;
if (param2 != null) {
params.put("N2", param2.value);
params.put("Nucleus2", param2.value);
}
break;
case "Purity":
case "Spectrometer Frequency":
key = "F1";
pageGlobals.freq = Double.parseDouble(val);
oval = Double.valueOf(pageGlobals.freq);
if (param2 != null) {
params.put("F2", Double.valueOf(param2.value));
params.put("Spectrometer Frequency2", Double.valueOf(param2.value));
}
break;
case "Spectrum Quality":
Expand Down Expand Up @@ -311,7 +309,11 @@ protected void report(String key, Object val) {
addProperty(IFDConst.IFD_PROPERTY_DESCRIPTION, val);
addProperty(IFDExtractor.PAGE_ID_PROPERTY_SOURCE, val);
}
addProperty(k == null ? key : k, val);
// SM and DIM are derived
if (!key.startsWith("!"))
addProperty(key, val);
if (k != null)
addProperty(k, val);
}

private void close() {
Expand All @@ -324,8 +326,8 @@ private void close() {
private void finalizeParams() {
if (params != null && pageGlobals.freq != 0) {
int f = getNominalFrequency(pageGlobals.freq, pageGlobals.nuc1);
params.put("SF", Double.valueOf(f));
params.put("DIM", Integer.valueOf(pageGlobals.dim) + "D");
params.put("!SF", Integer.valueOf(f));
params.put("!DIM", Integer.valueOf(pageGlobals.dim) + "D");
params.put("mnovaVersion", mnovaVersion);
}
params = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public IFDRepresentableObject(String label, String type) {
*/
@SuppressWarnings("unchecked")
public IFDRepresentation findOrAddRepresentation(String resourceID, String originPath, String rootPath, String localName, Object data, String type, String mediaType) {
String key = (data == null ? localName : data instanceof byte[] ? new String((byte[]) data) : data.toString());
String key = (localName != null ? localName : data instanceof byte[] ? new String((byte[]) data) : data.toString());
IFDRepresentation rep = getRepresentation(resourceID, key);
if (rep == null) {
rep = newRepresentation((localName == null ? null : new IFDReference(resourceID, originPath, rootPath, localName)), data, 0, type, mediaType);
rep = newRepresentation((localName == null ? null : new IFDReference(resourceID, originPath, rootPath, localName)), data, 0, type, mediaType);
add((T) rep);
map.put(resourceID + "::" + key, rep);
if (localName != null && data != null)
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/iupac/fairdata/core/IFDRepresentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public IFDRepresentation(IFDReference ref, Object data, long len, String type, S
//this.test = staticTest++;
this.ref = ref;
this.data = data;
// System.out.println(this.test + " " + subtype + " " + len + " " + ref);
// if (this.test == 44)
// System.out.println("IDFReptest");
this.len = (data instanceof String ? ((String) data).length()
: data instanceof byte[] ? ((byte[]) data).length
: ref != null || len != 0 ? len
Expand All @@ -61,7 +58,6 @@ public void setType(String type) {
}

public void setRef(IFDReference ref) {
System.out.println("IFDRep ref=" + ref);
this.ref = ref;
}

Expand Down

0 comments on commit 9b3eb3f

Please sign in to comment.