@SuppressWarnings("unchecked") @Test public void testStoreRepresentation() throws ResourceException { final List<BackgroundItem> capabilities = new ArrayList(1); capabilities.add(backgrounItemMock); final Set<Person> coordinators = new HashSet<Person>(); coordinators.add(personMock); setupCommonInitExpectations("validOrg"); context.checking(new Expectations() { { oneOf(orgMock).getCapabilities(); will(returnValue(capabilities)); oneOf(backgrounItemMock).getName(); will(returnValue("testCapability")); oneOf(orgMock).getCoordinators(); will(returnValue(coordinators)); oneOf(personMock).getOpenSocialId(); will(returnValue("testAcctountId")); oneOf(entityMapper).findByShortName(with(any(String.class))); will(returnValue(orgMock)); oneOf(orgMock).setCapabilities(with(any(ArrayList.class))); oneOf(entityMapper).flush(); } }); StringRepresentation jsonRep = new StringRepresentation(sut.convertEntityToJSONObject(orgMock).toString()); sut.init(restContext, request, response); sut.storeRepresentation(jsonRep); }
@Override public void storeRepresentation(final Representation entity) throws ResourceException { verifyEntityShortNameParam(); CompositeEntity cmpEnt = (CompositeEntity) this.getEntityByShortName(entityShortName); try { String jsontext = entity.getText(); JSONObject jsonObject = JSONObject.fromObject(jsontext); JSONArray jsonCapabilities = jsonObject.getJSONArray(CAP_ARRAY_KEY); 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) { String msg = "Unable to persist entity capabilities to overview for " + entityShortName; log.error(msg, e); getAdaptedResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getAdaptedResponse().setEntity(msg, MediaType.TEXT_PLAIN); } }
CompositeEntityCapabilityResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { verifyEntityShortNameParam(); CompositeEntity cmpEnt = (CompositeEntity) this.getEntityByShortName(entityShortName); try { String jsontext = entity.getText(); JSONObject jsonObject = JSONObject.fromObject(jsontext); JSONArray jsonCapabilities = jsonObject.getJSONArray(CAP_ARRAY_KEY); 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) { String msg = "Unable to persist entity capabilities to overview for " + entityShortName; log.error(msg, e); getAdaptedResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getAdaptedResponse().setEntity(msg, MediaType.TEXT_PLAIN); } } }
CompositeEntityCapabilityResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { verifyEntityShortNameParam(); CompositeEntity cmpEnt = (CompositeEntity) this.getEntityByShortName(entityShortName); try { String jsontext = entity.getText(); JSONObject jsonObject = JSONObject.fromObject(jsontext); JSONArray jsonCapabilities = jsonObject.getJSONArray(CAP_ARRAY_KEY); 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) { String msg = "Unable to persist entity capabilities to overview for " + entityShortName; log.error(msg, e); getAdaptedResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getAdaptedResponse().setEntity(msg, MediaType.TEXT_PLAIN); } }  }
CompositeEntityCapabilityResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { verifyEntityShortNameParam(); CompositeEntity cmpEnt = (CompositeEntity) this.getEntityByShortName(entityShortName); try { String jsontext = entity.getText(); JSONObject jsonObject = JSONObject.fromObject(jsontext); JSONArray jsonCapabilities = jsonObject.getJSONArray(CAP_ARRAY_KEY); 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) { String msg = "Unable to persist entity capabilities to overview for " + entityShortName; log.error(msg, e); getAdaptedResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getAdaptedResponse().setEntity(msg, MediaType.TEXT_PLAIN); } }  void setEntityMapper(final CompositeEntityMapper inEntMapper); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); JSONObject convertEntityToJSONObject(final CompositeEntity inEntInfo); }
CompositeEntityCapabilityResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { verifyEntityShortNameParam(); CompositeEntity cmpEnt = (CompositeEntity) this.getEntityByShortName(entityShortName); try { String jsontext = entity.getText(); JSONObject jsonObject = JSONObject.fromObject(jsontext); JSONArray jsonCapabilities = jsonObject.getJSONArray(CAP_ARRAY_KEY); 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) { String msg = "Unable to persist entity capabilities to overview for " + entityShortName; log.error(msg, e); getAdaptedResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getAdaptedResponse().setEntity(msg, MediaType.TEXT_PLAIN); } }  void setEntityMapper(final CompositeEntityMapper inEntMapper); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); JSONObject convertEntityToJSONObject(final CompositeEntity inEntInfo); static final String CAP_ARRAY_KEY; static final String COORD_ARRAY_KEY; static final String URL_SHORTNAME_KEY; }