Skip to content

Commit

Permalink
#2340 code cleaning, todo added
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-rc committed Nov 24, 2017
1 parent 654174d commit 7dc27e3
Showing 1 changed file with 41 additions and 27 deletions.
Expand Up @@ -38,6 +38,7 @@
import de.metas.logging.LogManager;
import lombok.NonNull;
import lombok.ToString;
import lombok.Value;

/*
* #%L
Expand Down Expand Up @@ -68,6 +69,9 @@ public static final Builder builder()
return new Builder();
}

// services
final IADTableDAO tableDAO = Services.get(IADTableDAO.class);

private static final Logger logger = LogManager.getLogger(RelationTypeZoomProvider.class);

private final boolean directed;
Expand All @@ -88,16 +92,16 @@ private RelationTypeZoomProvider(final Builder builder)

isTableRecordIdTarget = builder.isTableRecordIdTarget();

source = isTableRecordIdTarget ? null : new ZoomProviderDestination(
builder.getSource_Reference_ID(),
source = isTableRecordIdTarget ? null : new ZoomProviderDestination(new ZoomProviderDestinationParameters(builder.getSource_Reference_ID(),
builder.getSourceTableRefInfoOrNull(),
builder.getSourceRoleDisplayName(),
isTableRecordIdTarget);
target = new ZoomProviderDestination(
isTableRecordIdTarget));

target = new ZoomProviderDestination(new ZoomProviderDestinationParameters(
builder.getTarget_Reference_ID(),
builder.getTargetTableRefInfoOrNull(),
builder.getTargetRoleDisplayName(),
isTableRecordIdTarget);
isTableRecordIdTarget));

}

Expand Down Expand Up @@ -205,7 +209,7 @@ private IPair<ZoomProviderDestination, ZoomProviderDestination> findSourceAndTar
{
final ZoomProviderDestination target = getTarget();
final ZoomProviderDestination source = getSource();

Check.assumeNotNull(source, "The Source cannot be null");

if (isDirected())
Expand Down Expand Up @@ -240,15 +244,12 @@ else if (source.getTableName().equals(target.getTableName()))

}

/**
* @return a query which will find all zoomSource references in given target
*/
private MQuery mkZoomOriginQuery(final IZoomSource zoomOrigin)
{
final String queryWhereClause = createZoomOriginQueryWhereClause (zoomOrigin);
final String queryWhereClause = createZoomOriginQueryWhereClause(zoomOrigin);

final ITableRefInfo refTable = getTarget().getTableRefInfo();

final String tableName = refTable.getTableName();
final String columnName = refTable.getKeyColumn();

Expand All @@ -262,8 +263,7 @@ private MQuery mkZoomOriginQuery(final IZoomSource zoomOrigin)

private String createZoomOriginQueryWhereClause(final IZoomSource zoomOrigin)
{
final IADTableDAO tableDAO = Services.get(IADTableDAO.class);


final StringBuilder queryWhereClause = new StringBuilder();

final ITableRefInfo refTable = getTarget().getTableRefInfo();
Expand All @@ -272,13 +272,13 @@ private String createZoomOriginQueryWhereClause(final IZoomSource zoomOrigin)

if (isTableRecordIdTarget)
{

// TODO: Here we will implement the support for Prefix_Table_ID and Prefix_Record_ID (https://github.com/metasfresh/metasfresh/issues/3058)
final I_AD_Column recordIdColumn = tableDAO.retrieveColumnOrNull(tableName, ITableRecordReference.COLUMNNAME_Record_ID);

Check.assumeNotNull(recordIdColumn, "The table {} must have and AD_Table_ID and a Record_ID column to be used in a TableRecordIdTarget relation type", tableName);

final I_AD_Column adTableIdColumn = tableDAO.retrieveColumnOrNull(tableName, ITableRecordReference.COLUMNNAME_AD_Table_ID);

Check.assumeNotNull(adTableIdColumn, "The table {} must have and AD_Table_ID and a Record_ID column to be used in a TableRecordIdTarget relation type", tableName);

queryWhereClause
Expand Down Expand Up @@ -309,11 +309,10 @@ private String createZoomOriginQueryWhereClause(final IZoomSource zoomOrigin)
throw new AdempiereException("RefTable " + refTable + " has no whereClause, so RelationType " + this + " needs to be explicit");
}
}

return queryWhereClause.toString();
}


/**
* Parses given <code>where</code>
*
Expand Down Expand Up @@ -377,7 +376,7 @@ private static void updateRecordsCountAndZoomValue(final MQuery query)
public <T> List<T> retrieveDestinations(final Properties ctx, final PO zoomOriginPO, final Class<T> clazz, final String trxName)
{
final IZoomSource zoomOrigin = POZoomSource.of(zoomOriginPO, -1);

final MQuery query = mkZoomOriginQuery(zoomOrigin);

return new Query(ctx, query.getZoomTableName(), query.getWhereClause(false), trxName)
Expand All @@ -394,14 +393,17 @@ private static final class ZoomProviderDestination
private final ITranslatableString roleDisplayName;
private final boolean isTableRecordIdTarget;

private ZoomProviderDestination(final int AD_Reference_ID, @NonNull final ITableRefInfo tableRefInfo, @Nullable final ITranslatableString roleDisplayName, final boolean isReferenceTarget)
private ZoomProviderDestination(final ZoomProviderDestinationParameters zoomProviderDestinationParameters)

// final int AD_Reference_ID, @NonNull final ITableRefInfo tableRefInfo, @Nullable final ITranslatableString roleDisplayName, final boolean isReferenceTarget)
{
super();
Preconditions.checkArgument(AD_Reference_ID > 0, "AD_Reference_ID > 0");
this.AD_Reference_ID = AD_Reference_ID;
this.tableRefInfo = tableRefInfo;
this.roleDisplayName = roleDisplayName;
this.isTableRecordIdTarget = isReferenceTarget;
final int referenceId = zoomProviderDestinationParameters.getAD_Reference_ID();
Preconditions.checkArgument(referenceId > 0, "AD_Reference_ID > 0");
this.AD_Reference_ID = referenceId;
this.tableRefInfo = zoomProviderDestinationParameters.getTableRefInfo();
this.roleDisplayName = zoomProviderDestinationParameters.getRoleDisplayName();
this.isTableRecordIdTarget = zoomProviderDestinationParameters.isTableRecordIdTarget();

}

Expand Down Expand Up @@ -665,4 +667,16 @@ private boolean isTableRecordIdTarget()
}
}

@Value
public static class ZoomProviderDestinationParameters
{
private final int AD_Reference_ID;
@NonNull
private final ITableRefInfo tableRefInfo;
@Nullable
private final ITranslatableString roleDisplayName;
private final boolean tableRecordIdTarget;

}

}

0 comments on commit 7dc27e3

Please sign in to comment.