Skip to content

Commit

Permalink
Implement caching for JBrowseFieldUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber committed Feb 14, 2024
1 parent 1f51c0f commit eea1958
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 47 deletions.
74 changes: 74 additions & 0 deletions jbrowse/api-src/org/labkey/api/jbrowse/JBrowseFieldDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class JBrowseFieldDescriptor {

private Integer _flex = null;

private boolean _isLocked = false;

public JBrowseFieldDescriptor(String luceneFieldName, @Nullable String description, boolean isInDefaultColumns, boolean isIndexed, VCFHeaderLineType type, Integer orderKey) {
_fieldName = luceneFieldName;
_label = luceneFieldName;
Expand All @@ -37,22 +39,47 @@ public JBrowseFieldDescriptor(String luceneFieldName, @Nullable String descripti
_orderKey = orderKey;
}

@Override
public JBrowseFieldDescriptor clone()
{
JBrowseFieldDescriptor ret = new JBrowseFieldDescriptor(_fieldName, _description, _isInDefaultColumns, _isIndexed, _type, _orderKey);
ret._url = _url;
ret._label = _label;
ret._category = _category;
ret._flex = _flex;
ret._allowableValues = _allowableValues;
ret._colWidth = _colWidth;
ret._formatString = _formatString;
ret._isHidden = _isHidden;
ret._isMultiValued = _isMultiValued;

return ret;
}

public JBrowseFieldDescriptor hidden(boolean isHidden) {
throwIfLocked();

_isHidden = isHidden;
return this;
}

public JBrowseFieldDescriptor colWidth(String colWidth) {
throwIfLocked();

_colWidth = colWidth;
return this;
}

public JBrowseFieldDescriptor formatString(String formatString) {
throwIfLocked();

_formatString = formatString;
return this;
}

public JBrowseFieldDescriptor allowableValues(List<String> allowableValues) {
throwIfLocked();

_allowableValues = allowableValues == null ? null : Collections.unmodifiableList(allowableValues);

// Only change the value if we are certain there are multiple values:
Expand All @@ -65,15 +92,27 @@ public JBrowseFieldDescriptor allowableValues(List<String> allowableValues) {
}

public JBrowseFieldDescriptor multiValued(boolean isMultiValued) {
throwIfLocked();

_isMultiValued = isMultiValued;
return this;
}

public JBrowseFieldDescriptor label(String label) {
throwIfLocked();

_label = label;
return this;
}

private void throwIfLocked()
{
if (_isLocked)
{
throw new IllegalStateException("This JBrowseFieldDescriptor is locked!");
}
}

public String getFieldName() {
return _fieldName;
}
Expand Down Expand Up @@ -111,70 +150,105 @@ public String getColWidth() {
}

public void setLabel(String label) {
throwIfLocked();

_label = label;
}

public void setInDefaultColumns(boolean inDefaultColumns)
{
throwIfLocked();

_isInDefaultColumns = inDefaultColumns;
}

public void setCategory(String category)
{
throwIfLocked();

_category = category;
}

public void setUrl(String url)
{
throwIfLocked();

_url = url;
}

public void setMultiValued(boolean multiValued) {
throwIfLocked();

_isMultiValued = multiValued;
}

public void setHidden(boolean hidden) {
throwIfLocked();

_isHidden = hidden;
}

public void setIndexed(boolean indexed) {
throwIfLocked();

_isIndexed = indexed;
}

public void setColWidth(String colWidth) {
throwIfLocked();

_colWidth = colWidth;
}

public void setOrderKey(Integer orderKey) {
throwIfLocked();

_orderKey = orderKey;
}

public void setAllowableValues(List<String> allowableValues)
{
throwIfLocked();

_allowableValues = allowableValues;
}

public void setFormatString(String formatString)
{
throwIfLocked();

_formatString = formatString;
}

public void setDescription(String description)
{
throwIfLocked();

_description = description;
}

public void setFlex(Integer flex)
{
throwIfLocked();

_flex = flex;
}

public JBrowseFieldDescriptor inDefaultColumns(boolean isInDefaultColumns)
{
throwIfLocked();

_isInDefaultColumns = isInDefaultColumns;
return this;
}

public JBrowseFieldDescriptor lock()
{
_isLocked = true;

return this;
}

public JSONObject toJSON() {
JSONObject fieldDescriptorJSON = new JSONObject();
fieldDescriptorJSON.put("name", _fieldName);
Expand Down
12 changes: 12 additions & 0 deletions jbrowse/resources/queries/jbrowse/jsonfiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2012 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
var console = require("console");

function complete(){
// A little heavy-handed, but ensures we get this right:
console.log('Clearing JBrowseFieldUtils cache after update');
org.labkey.jbrowse.JBrowseFieldUtils.clearCache();
}
Loading

0 comments on commit eea1958

Please sign in to comment.