Skip to content

Commit

Permalink
Merge branch 'master' of github.com:metasfresh/metasfresh-webui-api
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Jul 11, 2018
2 parents 3e8b9ac + 028df69 commit 035f413
Showing 1 changed file with 54 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import de.metas.ui.web.document.filter.DocumentFilterParam;
import de.metas.ui.web.document.filter.DocumentFilterParam.Operator;
import de.metas.ui.web.window.datatypes.LookupValue;
import de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue;
import lombok.NonNull;

/*
Expand Down Expand Up @@ -159,8 +158,7 @@ private static HUTraceEventQuery updateProductIdFromParameter(
errorfIfNotEqualsOperator(parameter);
errorIfQueryValueGreaterThanZero("ProductId", query.getProductId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withProductId(value.getIdAsInt());
return query.withProductId(extractInt(parameter));
}

private static HUTraceEventQuery updateShipmentScheduleIdFromParameter(
Expand All @@ -169,8 +167,7 @@ private static HUTraceEventQuery updateShipmentScheduleIdFromParameter(
{
errorIfQueryValueGreaterThanZero("ShipmentScheduleId", query.getShipmentScheduleId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withShipmentScheduleId(value.getIdAsInt());
return query.withShipmentScheduleId(extractInt(parameter));
}

private static HUTraceEventQuery updatePpCostCollectorIdFromParameter(
Expand All @@ -179,8 +176,7 @@ private static HUTraceEventQuery updatePpCostCollectorIdFromParameter(
{
errorIfQueryValueGreaterThanZero("PpCostCollectorId", query.getPpCostCollectorId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withPpCostCollectorId(value.getIdAsInt());
return query.withPpCostCollectorId(extractInt(parameter));
}

private static HUTraceEventQuery updatePpOrderIdFromParameter(
Expand All @@ -189,8 +185,7 @@ private static HUTraceEventQuery updatePpOrderIdFromParameter(
{
errorIfQueryValueGreaterThanZero("PpOrderId", query.getPpOrderId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withPpOrderId(value.getIdAsInt());
return query.withPpOrderId(extractInt(parameter));
}

private static HUTraceEventQuery updateVhuIdFromParameter(
Expand All @@ -199,8 +194,7 @@ private static HUTraceEventQuery updateVhuIdFromParameter(
{
errorIfQueryValueGreaterThanZero("VhuId", query.getVhuId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withVhuId(value.getIdAsInt());
return query.withVhuId(extractInt(parameter));
}

private static HUTraceEventQuery updateVhuSourceIdFromParameter(
Expand All @@ -209,8 +203,7 @@ private static HUTraceEventQuery updateVhuSourceIdFromParameter(
{
errorIfQueryValueGreaterThanZero("VhuSourceId", query.getVhuSourceId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withVhuSourceId(value.getIdAsInt());
return query.withVhuSourceId(extractInt(parameter));
}

private static HUTraceEventQuery updateTypeFromParameter(
Expand All @@ -219,26 +212,23 @@ private static HUTraceEventQuery updateTypeFromParameter(
{
errorIfQueryValueNotNull("Type", query.getType(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withType(HUTraceType.valueOf(value.getIdAsString()));
return query.withType(HUTraceType.valueOf(extractString(parameter)));
}

private static HUTraceEventQuery updateVhuStatusFromParameter(
@NonNull final HUTraceEventQuery query, @NonNull final DocumentFilterParam parameter)
{
errorIfQueryValueNotEmpty("VhuStatus", query.getVhuStatus(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withVhuStatus(value.getIdAsString());
return query.withVhuStatus(extractString(parameter));
}

private static HUTraceEventQuery updateMovementIdFromParameter(
@NonNull final HUTraceEventQuery query, @NonNull final DocumentFilterParam parameter)
{
errorIfQueryValueGreaterThanZero("MovementId", query.getMovementId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withMovementId(value.getIdAsInt());
return query.withMovementId(extractInt(parameter));
}

private static HUTraceEventQuery updateHuTrxLineIdFromParameter(
Expand All @@ -247,8 +237,7 @@ private static HUTraceEventQuery updateHuTrxLineIdFromParameter(
{
errorIfQueryValueGreaterThanZero("TopLevelHuId", query.getHuTrxLineId(), query);

final IntegerLookupValue value = (IntegerLookupValue)parameter.getValue();
return query.withHuTrxLineId(value.getIdAsInt());
return query.withHuTrxLineId(extractInt(parameter));
}

private static HUTraceEventQuery updateTopLevelHuIdFromParameter(
Expand All @@ -257,8 +246,7 @@ private static HUTraceEventQuery updateTopLevelHuIdFromParameter(
{
errorIfQueryValueGreaterThanZero("TopLevelHuId", query.getTopLevelHuId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withTopLevelHuId(value.getIdAsInt());
return query.withTopLevelHuId(extractInt(parameter));
}

private static HUTraceEventQuery updateInOutIdFromParameter(
Expand All @@ -267,8 +255,7 @@ private static HUTraceEventQuery updateInOutIdFromParameter(
{
errorIfQueryValueGreaterThanZero("InOutId", query.getInOutId(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withInOutId(value.getIdAsInt());
return query.withInOutId(extractInt(parameter));
}

private static HUTraceEventQuery updateDocStatusFromParameter(
Expand All @@ -277,8 +264,7 @@ private static HUTraceEventQuery updateDocStatusFromParameter(
{
errorIfQueryValueNotEmpty("DocStatus", query.getDocStatus(), query);

final LookupValue value = (LookupValue)parameter.getValue();
return query.withDocStatus(value.getIdAsString());
return query.withDocStatus(extractString(parameter));
}

private static HUTraceEventQuery updateDocTypeIdFromParameter(
Expand All @@ -289,8 +275,8 @@ private static HUTraceEventQuery updateDocTypeIdFromParameter(
{
errorIfQueryValueGreaterThanZero("DocTypeId", query.getDocTypeId().getAsInt(), query);
}
final LookupValue value = (LookupValue)parameter.getValue();
return query.withDocTypeId(OptionalInt.of(value.getIdAsInt()));

return query.withDocTypeId(OptionalInt.of(extractInt(parameter)));
}

private static HUTraceEventQuery updateHuTraceIdFromParameter(@NonNull final HUTraceEventQuery query,
Expand All @@ -300,8 +286,8 @@ private static HUTraceEventQuery updateHuTraceIdFromParameter(@NonNull final HUT
{
errorIfQueryValueGreaterThanZero("HuTraceEventId", query.getHuTraceEventId().getAsInt(), query);
}
final LookupValue value = (LookupValue)parameter.getValue();
return query.withHuTraceEventId(OptionalInt.of(value.getIdAsInt()));

return query.withHuTraceEventId(OptionalInt.of(extractInt(parameter)));
}

private static HUTraceEventQuery updateOrgIdFromParameter(
Expand All @@ -310,8 +296,7 @@ private static HUTraceEventQuery updateOrgIdFromParameter(
{
errorIfQueryValueGreaterThanZero("OrgId", query.getOrgId(), query);

final IntegerLookupValue value = (IntegerLookupValue)parameter.getValue();
return query.withOrgId(value.getIdAsInt());
return query.withOrgId(extractInt(parameter));
}

private static void errorIfQueryValueGreaterThanZero(
Expand Down Expand Up @@ -358,4 +343,40 @@ private static void errorfIfNotEqualsOperator(@NonNull final DocumentFilterParam
throw new AdempiereException(message).setParameter("DocumentFilterParam", parameter);
}
}

private static int extractInt(@NonNull final DocumentFilterParam parameter)
{
final Object value = Check.assumeNotNull(parameter.getValue(), "Given paramter may not have a null value; parameter={}", parameter);

if (value instanceof LookupValue)
{
final LookupValue lookupValue = (LookupValue)value;
return lookupValue.getIdAsInt();
}
else if (value instanceof Integer)
{
return (Integer)value;
}

Check.fail("Unable to extract an integer ID from parameter={}", parameter);
return -1; // not reached
}

private static String extractString(@NonNull final DocumentFilterParam parameter)
{
final Object value = Check.assumeNotNull(parameter.getValue(), "Given paramter may not have a null value; parameter={}", parameter);

if (value instanceof LookupValue)
{
final LookupValue lookupValue = (LookupValue)value;
return lookupValue.getIdAsString();
}
else if (value instanceof Integer)
{
return (String)value;
}

Check.fail("Unable to extract a String from parameter={}", parameter);
return null; // not reached
}
}

0 comments on commit 035f413

Please sign in to comment.