Commit e5131f64 authored by Jasper Koehorst's avatar Jasper Koehorst
Browse files

working on fixing the duplicates

parent 5484876a
......@@ -7,6 +7,7 @@ import java.util.regex.Pattern;
* Metadata object based on MIXS (excel) file adapted to ISA structure.
*/
public class Metadata implements Serializable {
private static final long serialVersionUID = 7208928741154500357L;
private String aPackage;
private String structuredCommentName;
......@@ -19,6 +20,17 @@ public class Metadata implements Serializable {
private String preferredUnit;
private String label;
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Metadata))
return false;
Metadata other = (Metadata) o;
return (this.structuredCommentName == null && other.structuredCommentName == null)
|| (this.structuredCommentName != null && this.structuredCommentName.equals(other.structuredCommentName));
}
public String getPackage() {
return aPackage;
}
......
......@@ -100,7 +100,17 @@ public class MetadataParser extends Metadata {
}
metadata.setDefinition(row.getCell(index.get("definition")).getStringCellValue());
metadata.setRegex(generateRegex(metadata.getSyntax(), metadata.getExample()));
metadataSet.add(metadata);
// Check if metadata structured comment name is already used
boolean exists = false;
for (Metadata metadata1 : metadataSet) {
if (metadata.getPackage().equals(metadata1.getPackage()) && metadata.getStructuredCommentName().equals(metadata1.getStructuredCommentName())) {
exists = true;
logger.warn("A name has already been used, ignoring next entry with name " + metadata1.getStructuredCommentName());
}
}
if (!exists)
metadataSet.add(metadata);
}
}
return metadataSet;
......@@ -200,22 +210,22 @@ public class MetadataParser extends Metadata {
* @return objects per sheet in the metadata excel file
*/
public static SortedMap<String, ArrayList<Metadata>> main() {
// If metadata object exists and timestamp check
if (new File("metadata.obj").lastModified() < new File("metadata.xlsx").lastModified()) {
logger.info("Removing metadata object as metadata.xlsx is newer than metadata.obj");
new File("metadata.obj").delete();
}
if (new File("metadata.obj").exists()) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("metadata.obj"));
SortedMap<String, ArrayList<Metadata>> metadata = (SortedMap<String, ArrayList<Metadata>>) ois.readObject(); // cast is needed.
ois.close();
logger.info("Loaded metadata object");
return metadata;
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
// // If metadata object exists and timestamp check
// if (new File("metadata.obj").lastModified() < new File("metadata.xlsx").lastModified()) {
// logger.info("Removing metadata object as metadata.xlsx is newer than metadata.obj");
// new File("metadata.obj").delete();
// }
// if (new File("metadata.obj").exists()) {
// try {
// ObjectInputStream ois = new ObjectInputStream(new FileInputStream("metadata.obj"));
// SortedMap<String, ArrayList<Metadata>> metadata = (SortedMap<String, ArrayList<Metadata>>) ois.readObject(); // cast is needed.
// ois.close();
// logger.info("Loaded metadata object");
// return metadata;
// } catch (IOException | ClassNotFoundException e) {
// e.printStackTrace();
// }
// }
// If metadata file exists locally
InputStream is;
......@@ -227,12 +237,12 @@ public class MetadataParser extends Metadata {
try {
java.net.URL url = MetadataParser.class.getResource("/metadata.xlsx");
if (new Date(url.openConnection().getLastModified()).after(new Date(xlsxFile.lastModified()))) {
while (xlsxFile.exists()) {
logger.info("A newer excel file has been detected inside the JAR, overwriting now");
xlsxFile.delete();
}
// while (xlsxFile.exists()) {
logger.warn("A newer excel file has been detected inside the JAR, but using the existing excel file");
// xlsxFile.delete();
// }
} else {
logger.info("The excel file outside the jar is newer. Leaving the file intact.");
logger.info("Using the excel file outside the jar");
}
} catch (IOException e) {
e.printStackTrace();
......
......@@ -50,7 +50,7 @@ import static nl.fairbydesign.backend.WebGeneric.getFileContentFromResources;
import static nl.fairbydesign.backend.parsers.ExcelGenerator.makeAssaySheetOnly;
/**
* The view to create an excel file to fill in project metadata
* The view to create an Excel file to fill in project metadata
*/
@Route(value = "template", layout = MainView.class)
@PageTitle("Metadata Template Generator")
......@@ -306,6 +306,7 @@ public class TemplateView extends Div {
gridSelection.asMultiSelect().addValueChangeListener(event -> {
// Check if the package was selected
gridSelection.asMultiSelect().select(obligatoryList);
logger.info("Selected " + gridSelection.getSelectedItems().size() + " items");
});
// Additional fields to be added and enable field
......@@ -362,6 +363,8 @@ public class TemplateView extends Div {
// Listener for package selection
listBox.addValueChangeListener(listener -> {
// Ensure erase when new type is being selected
obligatoryList.removeAll(obligatoryList);
// System.err.println(metadata + " VALUE " + listener.getValue());
if (metadata.matches("ObservationUnit"))
packages.set(0, listener.getValue());
......@@ -378,11 +381,12 @@ public class TemplateView extends Div {
// Only show items when a true package is selected
if (!listener.getValue().contains("Select a package")) {
// Add all user items when package change occurs
logger.info("User lisr size " + userList);
items.get().addAll(userList);
// Add the metadata elements from selected package
for (Metadata m : metadataSet.get(metadata)) {
// Add all elements matching the package, core or user specified values
// System.err.println(m.getPackage() + " " + listBox.getValue() + " " + m.getPackage().matches(listBox.getValue()));
logger.info("Package: " + m.getPackage() + " " + listBox.getValue() + " " + m.getPackage().matches(listBox.getValue()));
if (m.getPackage().matches(listBox.getValue()) || m.getPackage().matches("core")) {
items.get().add(m);
// Obligatory items to be added to list for selection
......@@ -395,7 +399,7 @@ public class TemplateView extends Div {
if (metadata.toLowerCase().matches(".*assay$")) {
for (Metadata m : metadataSet.get("Assay")) {
// Add all elements matching the package, core or user specified values
System.err.println(m.getPackage() + " " + listBox.getValue() + " " + m.getPackage().matches(listBox.getValue()));
// System.err.println(m.getPackage() + " " + listBox.getValue() + " " + m.getPackage().matches(listBox.getValue()));
if (m.getPackage().matches(listBox.getValue()) || m.getPackage().matches("core")) {
items.get().add(m);
// Obligatory items to be added to list for selection
......
<br>
<div class="footer">
<p> © 2021 UNLOCK (<a href="http://download.systemsbiology.nl/unlock/">Download</a> / <a href="http://git.wur.nl/unlock/interface">Source code</a>)</p>
<p> © 2021 UNLOCK (<a href="http://download.systemsbiology.nl/unlock/">Download</a> / <a href="http://git.wur.nl/unlock/fairds">Source code</a>)</p>
</div>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment