public void storeRepresentation(final Representation entity) throws ResourceException
{
verifyEntityShortNameParam();
//get entity first because if this fails, no reason to do anything else.
CompositeEntity cmpEnt = (CompositeEntity) this.getEntityByShortName(entityShortName);
try
{
String jsontext = entity.getText();
JSONObject jsonObject = JSONObject.fromObject(jsontext);
JSONArray jsonCapabilities = jsonObject.getJSONArray(CAP_ARRAY_KEY);
//create list of capabilities from json.
List<BackgroundItem> capabilities = new ArrayList<BackgroundItem>(jsonCapabilities.size());
for (Object capability : jsonCapabilities)
{
if (Pattern.matches(REGEXP_PATTERN, (String) capability))
{
capabilities.add(new BackgroundItem((String) capability,
BackgroundItemType.CAPABILITY));
}
else
{
String msg = "Capability: " + (String) capability + " contains invalid characters. "
+ "Valid characters include alphanumeric, space, (!@$%^&*#-.,')";
log.error(msg);
JSONObject validationErrors = new JSONObject();
validationErrors.put(VALIDATION_ERRORS_KEY, msg);
getAdaptedResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
getAdaptedResponse().setEntity(validationErrors.toString(), MediaType.APPLICATION_JSON);
return;
}
}
cmpEnt.setCapabilities(capabilities);
entityMapper.flush();
}
catch (Exception e)
{