Skip to content

Commit

Permalink
use java command wrappers and params to create plates (#1864)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-chrisj authored Mar 22, 2024
1 parent a02b4da commit 26d6f11
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/org/labkey/remoteapi/plate/CreatePlateSetCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.labkey.remoteapi.plate;

import org.json.JSONObject;
import org.labkey.remoteapi.PostCommand;

public class CreatePlateSetCommand extends PostCommand<PlateSetResponse>
{
private final PlateSetParams _plateSetParams;
public CreatePlateSetCommand(PlateSetParams params)
{
super("plate", "createPlateSet");
setRequiredVersion(0);
_plateSetParams = params;
}

@Override
protected PlateSetResponse createResponse(String text, int status, String contentType, JSONObject json)
{
return new PlateSetResponse(text, status, contentType, json);
}

@Override
public JSONObject getJsonObject()
{
return _plateSetParams.toJSON();
}
}
116 changes: 116 additions & 0 deletions src/org/labkey/remoteapi/plate/PlateSetParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.labkey.remoteapi.plate;


import org.json.JSONObject;

public class PlateSetParams
{
private String _name = null;
private String _description = null;
private PlateSetType _type = null;
private Integer _id = null;
private Integer _parentPlateSetId = null;

public PlateSetParams()
{
}

public PlateSetParams(JSONObject json)
{
_name = json.getString("name");
_description = json.optString("description", null);
_type = PlateSetType.fromName(json.optString("type", null));
_id = json.getInt("rowId");
_parentPlateSetId = json.optIntegerObject("parentPlateSetId", null);
}

public JSONObject toJSON()
{
JSONObject json = new JSONObject();
json.put("name", _name);
json.put("description", _description);
if (_type != null)
json.put("type", _type.getType());
json.put("rowId", _id);
json.put("parentPlateSetId", _parentPlateSetId);
return json;
}

public PlateSetParams setName(String name)
{
_name = name;
return this;
}

public String getName()
{
return _name;
}

public PlateSetParams setDescription(String description)
{
_description = description;
return this;
}

public String getDescription()
{
return _description;
}

public PlateSetParams setType(PlateSetType type)
{
_type = type;
return this;
}

public PlateSetType getType()
{
return _type;
}

public Integer getId()
{
return _id;
}

public PlateSetParams setParentPlateSetId(Integer parentPlateSetId)
{
_parentPlateSetId = parentPlateSetId;
return this;
}

public Integer getParentPlateSetId()
{
return _parentPlateSetId;
}


public enum PlateSetType
{
Primary("primary"),
Assay("assay");

PlateSetType(String type)
{
this._type = type;
}
private final String _type;
public String getType()
{
return _type;
}
public static PlateSetType fromName(String type)
{
if (type != null)
{
for (PlateSetType plateSetType : PlateSetType.values())
{
if (type.equalsIgnoreCase(plateSetType.getType()))
return plateSetType;
}
}
return null;
}
}
}
20 changes: 20 additions & 0 deletions src/org/labkey/remoteapi/plate/PlateSetResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.labkey.remoteapi.plate;

import org.json.JSONObject;
import org.labkey.remoteapi.CommandResponse;

public class PlateSetResponse extends CommandResponse
{
private final PlateSetParams _plateSetParams;

public PlateSetResponse(String text, int statusCode, String contentType, JSONObject json)
{
super(text, statusCode, contentType, json);
_plateSetParams = new PlateSetParams(json.getJSONObject("data"));
}

public PlateSetParams getPlateSetParams()
{
return _plateSetParams;
}
}

0 comments on commit 26d6f11

Please sign in to comment.