@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testAppendOptionalFieldsNoOptionsGiven() { MultivaluedMap map = new MultivaluedMapImpl(); EntityBody body = new EntityBody(); body.put("student", "{\"somekey\":\"somevalue\"}"); List<EntityBody> entities = new ArrayList<EntityBody>(); entities.add(body); entities = optionalView.add(entities, ResourceNames.SECTIONS, map); assertEquals("Should only have one", 1, entities.size()); assertEquals("Should match", body, entities.get(0)); }
@Override public List<EntityBody> add(List<EntityBody> entities, final String resource, MultivaluedMap<String, String> queryParams) { if (factory == null) { return entities; } List<EntityBody> appendedEntities = entities; List<String> optionalFields = new ArrayList<String>(); if (queryParams.get(ParameterConstants.OPTIONAL_FIELDS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.OPTIONAL_FIELDS)); } if (queryParams.get(ParameterConstants.VIEWS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.VIEWS)); } if (!optionalFields.isEmpty()) { for (String type : optionalFields) { for (String appenderType : type.split(",")) { Map<String, String> values = extractOptionalFieldParams(appenderType); OptionalFieldAppender appender = factory.getOptionalFieldAppender(resource + "_" + values.get(OptionalFieldAppenderFactory.APPENDER_PREFIX)); if (appender != null) { appendedEntities = appender.applyOptionalField(entities, values.get(OptionalFieldAppenderFactory.PARAM_PREFIX)); } } } } return appendedEntities; }
OptionalView implements View { @Override public List<EntityBody> add(List<EntityBody> entities, final String resource, MultivaluedMap<String, String> queryParams) { if (factory == null) { return entities; } List<EntityBody> appendedEntities = entities; List<String> optionalFields = new ArrayList<String>(); if (queryParams.get(ParameterConstants.OPTIONAL_FIELDS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.OPTIONAL_FIELDS)); } if (queryParams.get(ParameterConstants.VIEWS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.VIEWS)); } if (!optionalFields.isEmpty()) { for (String type : optionalFields) { for (String appenderType : type.split(",")) { Map<String, String> values = extractOptionalFieldParams(appenderType); OptionalFieldAppender appender = factory.getOptionalFieldAppender(resource + "_" + values.get(OptionalFieldAppenderFactory.APPENDER_PREFIX)); if (appender != null) { appendedEntities = appender.applyOptionalField(entities, values.get(OptionalFieldAppenderFactory.PARAM_PREFIX)); } } } } return appendedEntities; } }
OptionalView implements View { @Override public List<EntityBody> add(List<EntityBody> entities, final String resource, MultivaluedMap<String, String> queryParams) { if (factory == null) { return entities; } List<EntityBody> appendedEntities = entities; List<String> optionalFields = new ArrayList<String>(); if (queryParams.get(ParameterConstants.OPTIONAL_FIELDS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.OPTIONAL_FIELDS)); } if (queryParams.get(ParameterConstants.VIEWS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.VIEWS)); } if (!optionalFields.isEmpty()) { for (String type : optionalFields) { for (String appenderType : type.split(",")) { Map<String, String> values = extractOptionalFieldParams(appenderType); OptionalFieldAppender appender = factory.getOptionalFieldAppender(resource + "_" + values.get(OptionalFieldAppenderFactory.APPENDER_PREFIX)); if (appender != null) { appendedEntities = appender.applyOptionalField(entities, values.get(OptionalFieldAppenderFactory.PARAM_PREFIX)); } } } } return appendedEntities; }  }
OptionalView implements View { @Override public List<EntityBody> add(List<EntityBody> entities, final String resource, MultivaluedMap<String, String> queryParams) { if (factory == null) { return entities; } List<EntityBody> appendedEntities = entities; List<String> optionalFields = new ArrayList<String>(); if (queryParams.get(ParameterConstants.OPTIONAL_FIELDS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.OPTIONAL_FIELDS)); } if (queryParams.get(ParameterConstants.VIEWS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.VIEWS)); } if (!optionalFields.isEmpty()) { for (String type : optionalFields) { for (String appenderType : type.split(",")) { Map<String, String> values = extractOptionalFieldParams(appenderType); OptionalFieldAppender appender = factory.getOptionalFieldAppender(resource + "_" + values.get(OptionalFieldAppenderFactory.APPENDER_PREFIX)); if (appender != null) { appendedEntities = appender.applyOptionalField(entities, values.get(OptionalFieldAppenderFactory.PARAM_PREFIX)); } } } } return appendedEntities; }  @Override List<EntityBody> add(List<EntityBody> entities, final String resource, MultivaluedMap<String, String> queryParams); }
OptionalView implements View { @Override public List<EntityBody> add(List<EntityBody> entities, final String resource, MultivaluedMap<String, String> queryParams) { if (factory == null) { return entities; } List<EntityBody> appendedEntities = entities; List<String> optionalFields = new ArrayList<String>(); if (queryParams.get(ParameterConstants.OPTIONAL_FIELDS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.OPTIONAL_FIELDS)); } if (queryParams.get(ParameterConstants.VIEWS) != null) { optionalFields.addAll(queryParams.get(ParameterConstants.VIEWS)); } if (!optionalFields.isEmpty()) { for (String type : optionalFields) { for (String appenderType : type.split(",")) { Map<String, String> values = extractOptionalFieldParams(appenderType); OptionalFieldAppender appender = factory.getOptionalFieldAppender(resource + "_" + values.get(OptionalFieldAppenderFactory.APPENDER_PREFIX)); if (appender != null) { appendedEntities = appender.applyOptionalField(entities, values.get(OptionalFieldAppenderFactory.PARAM_PREFIX)); } } } } return appendedEntities; }  @Override List<EntityBody> add(List<EntityBody> entities, final String resource, MultivaluedMap<String, String> queryParams);  }