package ca.carleton.gcrc.couch.onUpload.conversion;
import net.sf.json.JSONObject;
import ca.carleton.gcrc.couch.onUpload.UploadConstants;
public class WorkDescriptor extends AbstractDescriptor {
private AttachmentDescriptor attDescription;
public WorkDescriptor(AttachmentDescriptor attDescription){
this.attDescription = attDescription;
}
public boolean isKeyAvailable(String key){
JSONObject descriptionObj = getJson();
return descriptionObj.containsKey(key);
}
public String getStringAttribute(String key) {
String value = null;
JSONObject descriptionObj = getJson();
if( descriptionObj.containsKey(key) ) {
value = descriptionObj.getString(key);
}
return value;
}
public void setStringAttribute(String key, String value) {
JSONObject descriptionObj = getJson();
descriptionObj.put(key,value);
attDescription.setSavingRequired(true);
}
public void removeAttribute(String key) {
JSONObject descriptionObj = getJson();
if( descriptionObj.containsKey(key) ) {
descriptionObj.remove(key);
attDescription.setSavingRequired(true);
}
}
@Override
protected JSONObject getJson(){
JSONObject attachmentDescription = attDescription.getJson();
return attachmentDescription.getJSONObject(UploadConstants.WORK_KEY);
}
@Override
protected void setSavingRequired(boolean flag) {
attDescription.setSavingRequired(flag);
}
}