Refactor code
rename discoveryFilter to makeQueryString
more readble
@@ -249,7 +249,7 @@ public class ServiceLayerImplHttp implements ServiceLayer {
try {
// Add parameters to URI
- req.to = discoveryFilter(req);
+ req.to = makeQueryString(req);
} catch (Exception e) {
LOGGER.warn("Create filter error.", e);
return null;
@@ -284,7 +284,7 @@ public class ServiceLayerImplHttp implements ServiceLayer {
try {
// Add parameters to URI
- req.to = discoveryFilter(req);
+ req.to = makeQueryString(req);
} catch (Exception e) {
LOGGER.warn("Create filter error.", e);
return null;
@@ -369,19 +369,18 @@ public class ServiceLayerImplHttp implements ServiceLayer {
return resArrayList;
}
- public static String discoveryFilter(RequestPrimitiveDTO req) {
+ private static String makeQueryString(RequestPrimitiveDTO req) {
if (req.to == null) {
LOGGER.warn("URI is NULL");
return req.to;
}
- String ex = req.to;
+ String ex = "";
try {
- Boolean questionFlg = false;
- Boolean filterFlg = req.filterCriteria != null ? true : false;
- Boolean resultTypeFlg = req.discoveryResultType != null ? true : false;
+ boolean filterFlg = (req.filterCriteria != null);
+ boolean resultTypeFlg = (req.discoveryResultType != null);
if (filterFlg) {
// Get field of filterCriteria
@@ -391,10 +390,6 @@ public class ServiceLayerImplHttp implements ServiceLayer {
// Process only the number of items in the field
for (Field s : field) {
if (s.get(fc) != null) {
- if (!questionFlg) {
- ex += "?";
- questionFlg = true;
- }
// Whether the type is List
if (s.getType().equals(List.class)) {
Type t = s.getGenericType();
@@ -430,6 +425,7 @@ public class ServiceLayerImplHttp implements ServiceLayer {
else if ("filterUsage".equals(s.getName())) {
ex += LongShortConverter.l2s(s.getName()) + "=" + fc.filterUsage.getValue();
}
+
else {
for (int i = 0; field.length > i; i++) {
if (field[i].getName().equals(s.getName())) {
@@ -446,25 +442,20 @@ public class ServiceLayerImplHttp implements ServiceLayer {
continue;
}
ex += "&";
- }
+ }// end of for
}
// Setting the ResultType and the URI that added the query more than once
- if (resultTypeFlg && questionFlg) {
+ if (resultTypeFlg ) {
ex += "drt=" + req.discoveryResultType.getValue();
+ }else {
+ ex = ex.substring(0, ex.length() - 1); // remove '&' at the tail
}
- // Setting of ResultType setting
- else if (resultTypeFlg) {
- ex += "?drt=" + req.discoveryResultType.getValue();
- }
- // URI with no ResultType setting and one or more queries added
- else if (questionFlg) {
- ex = ex.substring(0, ex.length() - 1);
- }
+
} catch (Exception e) {
LOGGER.warn("Create filter error.", e);
}
- return ex;
+ return req.to + "?" + ex;
}
private Request makeCRUDRequest(RequestPrimitiveDTO req) {
