iRequest.data.commandInfo = "Studio add property";
try {
OType type = OType.valueOf(fields.get("type"));
OPropertyImpl prop;
if (type == OType.LINK || type == OType.LINKLIST || type == OType.LINKSET || type == OType.LINKMAP)
prop = (OPropertyImpl) cls.createProperty(fields.get("name"), type,
db.getMetadata().getSchema().getClass(fields.get("linkedClass")));
else
prop = (OPropertyImpl) cls.createProperty(fields.get("name"), type);
if (fields.get("linkedType") != null)
prop.setLinkedType(OType.valueOf(fields.get("linkedType")));
if (fields.get("mandatory") != null)
prop.setMandatory("on".equals(fields.get("mandatory")));
if (fields.get("notNull") != null)
prop.setNotNull("on".equals(fields.get("notNull")));
if (fields.get("min") != null)
prop.setMin(fields.get("min"));
if (fields.get("max") != null)
prop.setMax(fields.get("max"));
if (fields.get("indexed") != null)
prop.createIndex(fields.get("indexed").equals("Unique") ? OProperty.INDEX_TYPE.UNIQUE : OProperty.INDEX_TYPE.NOTUNIQUE);
sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN,
"Property " + fields.get("name") + " created successfully with id=" + prop.getId());
} catch (Exception e) {
sendTextContent(iRequest, OHttpUtils.STATUS_INTERNALERROR, "Error on creating a new property in class " + rid + ": " + e,
null, OHttpUtils.CONTENT_TEXT_PLAIN, "Error on creating a new property in class " + rid + ": " + e);
}