aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Kornilov2014-08-05 05:47:17 (EDT)
committerLukas Jungmann2014-08-05 12:15:05 (EDT)
commitf9867f93871f0be29e7eaccf9cc0c8e2c1d93fb0 (patch)
treeab0ebd8dfe8133c4fa105ced9ac5598ac9989fc2
parentfa1bc56529349bbe83173fd5b307cda5c89426ee (diff)
downloadeclipselink.runtime-f9867f93871f0be29e7eaccf9cc0c8e2c1d93fb0.zip
eclipselink.runtime-f9867f93871f0be29e7eaccf9cc0c8e2c1d93fb0.tar.gz
eclipselink.runtime-f9867f93871f0be29e7eaccf9cc0c8e2c1d93fb0.tar.bz2
Bug #441152: JPARS fields filtering parameter exclFields renamed to excludeFields. A test added.
Signed-off-by: Dmitry Kornilov <dmitry.kornilov@oracle.com>
-rw-r--r--dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/exceptions/JPARSException.java16
-rw-r--r--dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/FeatureSet.java2
-rw-r--r--dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/fieldsfiltering/FieldsFilteringValidator.java15
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/JPARSErrorCodes.java1
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/i18n/JPARSExceptionResource.java1
-rw-r--r--jpa/eclipselink.jpars.test/src/org/eclipse/persistence/jpars/test/server/ServerFieldsFilteringTest.java24
6 files changed, 43 insertions, 16 deletions
diff --git a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/exceptions/JPARSException.java b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/exceptions/JPARSException.java
index 70f589d..fe10f37 100644
--- a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/exceptions/JPARSException.java
+++ b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/exceptions/JPARSException.java
@@ -171,6 +171,22 @@ public class JPARSException extends EclipseLinkException {
}
/**
+ * Both fields and excludeFields parameters are present in request.
+ *
+ * @return the JPARS exception
+ */
+ public static JPARSException fieldsFilteringBothParametersPresent() {
+ Object[] args = {};
+
+ String msg = ExceptionMessageGenerator.buildMessage(JPARSException.class, JPARSErrorCodes.FIELDS_FILTERING_BOTH_PARAMETERS_PRESENT, args);
+ JPARSException exception = new JPARSException(msg);
+ exception.setErrorCode(JPARSErrorCodes.FIELDS_FILTERING_BOTH_PARAMETERS_PRESENT);
+ exception.setHttpStatusCode(Status.BAD_REQUEST);
+
+ return exception;
+ }
+
+ /**
* Database mapping could not be found for entity attribute.
*
* @param attributeName the attribute name
diff --git a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/FeatureSet.java b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/FeatureSet.java
index 46d4134..2ee2962 100644
--- a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/FeatureSet.java
+++ b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/FeatureSet.java
@@ -24,7 +24,7 @@ public interface FeatureSet {
/* Pageable resources */
PAGING,
- /* Fields filtering (fields, exclFields query parameters) */
+ /* Fields filtering (fields, excludeFields query parameters) */
FIELDS_FILTERING
}
diff --git a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/fieldsfiltering/FieldsFilteringValidator.java b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/fieldsfiltering/FieldsFilteringValidator.java
index 641adcd..749aaa6 100644
--- a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/fieldsfiltering/FieldsFilteringValidator.java
+++ b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/features/fieldsfiltering/FieldsFilteringValidator.java
@@ -31,9 +31,8 @@ import java.util.Map;
*/
public final class FieldsFilteringValidator {
public static final String FIELDS_PARAM_NAME = "fields";
- public static final String EXCL_FIELDS_PARAM_NAME = "exclFields";
+ public static final String EXCL_FIELDS_PARAM_NAME = "excludeFields";
- private final UriInfo uri;
private final Object entity;
private final PersistenceContext context;
private final Map<String, Object> queryParameters;
@@ -46,7 +45,6 @@ public final class FieldsFilteringValidator {
*/
public FieldsFilteringValidator(PersistenceContext context, UriInfo uri, Object entity) {
queryParameters = AbstractResource.getQueryParameters(uri);
- this.uri = uri;
this.entity = entity;
this.context = context;
}
@@ -62,18 +60,17 @@ public final class FieldsFilteringValidator {
return false;
}
- // Throw exception if both 'fields' and 'exclFields' present
+ // Throw exception if both 'fields' and 'excludeFields' present
if (queryParameters.containsKey(FIELDS_PARAM_NAME) && queryParameters.containsKey(EXCL_FIELDS_PARAM_NAME)) {
- // TODO throw the right exception
- throw new IllegalArgumentException("");
+ throw JPARSException.fieldsFilteringBothParametersPresent();
}
if (queryParameters.containsKey(FIELDS_PARAM_NAME)) {
// fields
fields = Arrays.asList(((String) queryParameters.get(FIELDS_PARAM_NAME)).split("\\s*,\\s*"));
} else {
- // exclFields
- List<String> exclFields = Arrays.asList(((String) queryParameters.get(EXCL_FIELDS_PARAM_NAME)).split("\\s*,\\s*"));
+ // excludeFields
+ List<String> excludeFields = Arrays.asList(((String) queryParameters.get(EXCL_FIELDS_PARAM_NAME)).split("\\s*,\\s*"));
// Get attribute mappings from class descriptor. We just need an attributes list actually
List<DatabaseMapping> mappings = context.getServerSession().getProject().getDescriptors().get(entity.getClass()).getMappings();
@@ -81,7 +78,7 @@ public final class FieldsFilteringValidator {
// Build fields list as all fields without the excluded ones
fields = new ArrayList<String>();
for (DatabaseMapping mapping : mappings) {
- if (!exclFields.contains(mapping.getAttributeName())) {
+ if (!excludeFields.contains(mapping.getAttributeName())) {
fields.add(mapping.getAttributeName());
}
}
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/JPARSErrorCodes.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/JPARSErrorCodes.java
index dc4d49b..a675e45 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/JPARSErrorCodes.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/JPARSErrorCodes.java
@@ -32,6 +32,7 @@ public class JPARSErrorCodes {
public static final int RESPONSE_COULD_NOT_BE_BUILT_FOR_NAMED_QUERY_REQUEST = 61014;
public static final int INVALID_SERVICE_VERSION = 61015;
public static final int PAGINATION_PARAMETER_USED_FOR_NOT_PAGEABLE_RESOURCE = 61016;
+ public static final int FIELDS_FILTERING_BOTH_PARAMETERS_PRESENT = 61017;
//
public static final int AN_EXCEPTION_OCCURRED = 61999;
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/i18n/JPARSExceptionResource.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/i18n/JPARSExceptionResource.java
index 6dbc63f..04ea384 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/i18n/JPARSExceptionResource.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/exceptions/i18n/JPARSExceptionResource.java
@@ -40,6 +40,7 @@ public class JPARSExceptionResource extends ListResourceBundle {
{ String.valueOf(JPARSErrorCodes.RESPONSE_COULD_NOT_BE_BUILT_FOR_NAMED_QUERY_REQUEST), "Response for find named query request for query {0} in persistence unit {1} could not be built successfully." },
{ String.valueOf(JPARSErrorCodes.AN_EXCEPTION_OCCURRED), "{0} occurred." },
{ String.valueOf(JPARSErrorCodes.PAGINATION_PARAMETER_USED_FOR_NOT_PAGEABLE_RESOURCE), "Pagination query parameter (limit or offset) used for non-pageable resource." },
+ { String.valueOf(JPARSErrorCodes.FIELDS_FILTERING_BOTH_PARAMETERS_PRESENT), "Both 'fields' and 'excludeFields' cannot be used in the same request." },
};
@Override
diff --git a/jpa/eclipselink.jpars.test/src/org/eclipse/persistence/jpars/test/server/ServerFieldsFilteringTest.java b/jpa/eclipselink.jpars.test/src/org/eclipse/persistence/jpars/test/server/ServerFieldsFilteringTest.java
index ce8d418..926108f 100644
--- a/jpa/eclipselink.jpars.test/src/org/eclipse/persistence/jpars/test/server/ServerFieldsFilteringTest.java
+++ b/jpa/eclipselink.jpars.test/src/org/eclipse/persistence/jpars/test/server/ServerFieldsFilteringTest.java
@@ -122,10 +122,10 @@ public class ServerFieldsFilteringTest {
}
@Test
- public void testExclFieldsJson() throws URISyntaxException {
- // exclFields parameter
+ public void testExcludeFieldsJson() throws URISyntaxException {
+ // excludeFields parameter
final Map<String, String> hints = new HashMap<String, String>(1);
- hints.put("exclFields", "basketItems,name");
+ hints.put("excludeFields", "basketItems,name");
// Get BasketItem with id = 1
String queryResult = RestUtils.restReadWithHints(context, 1, Basket.class.getSimpleName(), hints, MediaType.APPLICATION_JSON_TYPE);
@@ -137,10 +137,10 @@ public class ServerFieldsFilteringTest {
}
@Test
- public void testExclFieldsXml() throws URISyntaxException {
- // exclFields parameter
+ public void testExcludeFieldsXml() throws URISyntaxException {
+ // excludeFields parameter
final Map<String, String> hints = new HashMap<String, String>(1);
- hints.put("exclFields", "basketItems,name");
+ hints.put("excludeFields", "basketItems,name");
// Get BasketItem with id = 1
String queryResult = RestUtils.restReadWithHints(context, 1, Basket.class.getSimpleName(), hints, MediaType.APPLICATION_XML_TYPE);
@@ -151,4 +151,16 @@ public class ServerFieldsFilteringTest {
assertFalse(queryResult.contains("<basketItems>"));
assertFalse(queryResult.contains("</basketItems>"));
}
+
+ @Test(expected = Exception.class)
+ public void testBothParametersPresent() throws URISyntaxException {
+ // excludeFields parameter
+ final Map<String, String> hints = new HashMap<String, String>(1);
+ hints.put("excludeFields", "basketItems,name");
+ hints.put("fields", "name,id");
+
+ // Get BasketItem with id = 1. Exception must be thrown because both 'fields' and 'excludeFields' parameters
+ // cannot be present in the same request.
+ RestUtils.restReadWithHints(context, 1, Basket.class.getSimpleName(), hints, MediaType.APPLICATION_XML_TYPE);
+ }
}