@Test public void testOneAuthor() { final JSONObject request = new JSONObject(); final String personName = "personName"; final JSONObject personObj = new JSONObject(); personObj.accumulate("type", "PERSON"); personObj.accumulate("name", personName); JSONArray recipientArr = new JSONArray(); recipientArr.add(personObj); request.accumulate("authoredBy", recipientArr); final Long personId = 5L; context.checking(new Expectations() { { oneOf(getPersonIdByAccountIdMapper).execute(personName); will(returnValue(personId)); } }); Assert.assertEquals("(p" + personId + ")", sut.transform(request, 0L)); context.assertIsSatisfied(); }
@Override public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray authors = request.getJSONArray("authoredBy"); StringBuilder authorsRequest = new StringBuilder(); if (authors == null || authors.size() == 0) { return ""; } authorsRequest.append("("); for (int i = 0; i < authors.size(); i++) { if (i > 0) { authorsRequest.append(" OR "); } JSONObject author = authors.getJSONObject(i); EntityType type = EntityType.valueOf(author.getString("type")); switch (type) { case PERSON: authorsRequest.append("p"); authorsRequest.append(getPersonIdByAccountIdMapper.execute(author.getString("name"))); break; case GROUP: authorsRequest.append("g"); authorsRequest.append(groupMapper.fetchId(author.getString("name"))); break; default: throw new IllegalArgumentException("Unhandled type."); } } authorsRequest.append(")"); return authorsRequest.toString(); }
AuthoredByPersistenceRequestTransformer implements PersistenceDataSourceRequestTransformer { @Override public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray authors = request.getJSONArray("authoredBy"); StringBuilder authorsRequest = new StringBuilder(); if (authors == null || authors.size() == 0) { return ""; } authorsRequest.append("("); for (int i = 0; i < authors.size(); i++) { if (i > 0) { authorsRequest.append(" OR "); } JSONObject author = authors.getJSONObject(i); EntityType type = EntityType.valueOf(author.getString("type")); switch (type) { case PERSON: authorsRequest.append("p"); authorsRequest.append(getPersonIdByAccountIdMapper.execute(author.getString("name"))); break; case GROUP: authorsRequest.append("g"); authorsRequest.append(groupMapper.fetchId(author.getString("name"))); break; default: throw new IllegalArgumentException("Unhandled type."); } } authorsRequest.append(")"); return authorsRequest.toString(); } }
AuthoredByPersistenceRequestTransformer implements PersistenceDataSourceRequestTransformer { @Override public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray authors = request.getJSONArray("authoredBy"); StringBuilder authorsRequest = new StringBuilder(); if (authors == null || authors.size() == 0) { return ""; } authorsRequest.append("("); for (int i = 0; i < authors.size(); i++) { if (i > 0) { authorsRequest.append(" OR "); } JSONObject author = authors.getJSONObject(i); EntityType type = EntityType.valueOf(author.getString("type")); switch (type) { case PERSON: authorsRequest.append("p"); authorsRequest.append(getPersonIdByAccountIdMapper.execute(author.getString("name"))); break; case GROUP: authorsRequest.append("g"); authorsRequest.append(groupMapper.fetchId(author.getString("name"))); break; default: throw new IllegalArgumentException("Unhandled type."); } } authorsRequest.append(")"); return authorsRequest.toString(); } AuthoredByPersistenceRequestTransformer(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final GetDomainGroupsByShortNames inGroupMapper); }
AuthoredByPersistenceRequestTransformer implements PersistenceDataSourceRequestTransformer { @Override public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray authors = request.getJSONArray("authoredBy"); StringBuilder authorsRequest = new StringBuilder(); if (authors == null || authors.size() == 0) { return ""; } authorsRequest.append("("); for (int i = 0; i < authors.size(); i++) { if (i > 0) { authorsRequest.append(" OR "); } JSONObject author = authors.getJSONObject(i); EntityType type = EntityType.valueOf(author.getString("type")); switch (type) { case PERSON: authorsRequest.append("p"); authorsRequest.append(getPersonIdByAccountIdMapper.execute(author.getString("name"))); break; case GROUP: authorsRequest.append("g"); authorsRequest.append(groupMapper.fetchId(author.getString("name"))); break; default: throw new IllegalArgumentException("Unhandled type."); } } authorsRequest.append(")"); return authorsRequest.toString(); } AuthoredByPersistenceRequestTransformer(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final GetDomainGroupsByShortNames inGroupMapper); @Override Serializable transform(final JSONObject request, final Long userEntityId); }
AuthoredByPersistenceRequestTransformer implements PersistenceDataSourceRequestTransformer { @Override public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray authors = request.getJSONArray("authoredBy"); StringBuilder authorsRequest = new StringBuilder(); if (authors == null || authors.size() == 0) { return ""; } authorsRequest.append("("); for (int i = 0; i < authors.size(); i++) { if (i > 0) { authorsRequest.append(" OR "); } JSONObject author = authors.getJSONObject(i); EntityType type = EntityType.valueOf(author.getString("type")); switch (type) { case PERSON: authorsRequest.append("p"); authorsRequest.append(getPersonIdByAccountIdMapper.execute(author.getString("name"))); break; case GROUP: authorsRequest.append("g"); authorsRequest.append(groupMapper.fetchId(author.getString("name"))); break; default: throw new IllegalArgumentException("Unhandled type."); } } authorsRequest.append(")"); return authorsRequest.toString(); } AuthoredByPersistenceRequestTransformer(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final GetDomainGroupsByShortNames inGroupMapper); @Override Serializable transform(final JSONObject request, final Long userEntityId);  }