Skip to content

Commit

Permalink
Fix warnings, add nullability info
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed Jun 17, 2020
1 parent 08d3e50 commit 7d2fce1
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 132 deletions.
@@ -1,24 +1,8 @@
package de.metas.bpartner;

import java.util.Objects;
import java.util.Optional;

import javax.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import de.metas.util.Check;
import de.metas.util.lang.RepoIdAware;
import lombok.Value;

/*
* #%L
* de.metas.adempiere.adempiere.base
* %%
* Copyright (C) 2018 metas GmbH
* Copyright (C) 2020 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Expand All @@ -36,6 +20,20 @@
* #L%
*/

package de.metas.bpartner;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import de.metas.util.Check;
import de.metas.util.lang.RepoIdAware;
import lombok.Value;

import javax.annotation.Nullable;
import java.util.Objects;
import java.util.Optional;

@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
@Value
public class BPartnerId implements RepoIdAware
Expand Down Expand Up @@ -63,12 +61,12 @@ public static Optional<BPartnerId> optionalOfRepoId(final int repoId)
return Optional.ofNullable(ofRepoIdOrNull(repoId));
}

public static int toRepoId(final BPartnerId bpartnerId)
public static int toRepoId(@Nullable final BPartnerId bpartnerId)
{
return toRepoIdOr(bpartnerId, -1);
}

public static int toRepoIdOr(final BPartnerId bpartnerId, final int defaultValue)
public static int toRepoIdOr(@Nullable final BPartnerId bpartnerId, final int defaultValue)
{
return bpartnerId != null ? bpartnerId.getRepoId() : defaultValue;
}
Expand Down
@@ -1,10 +1,8 @@
package org.adempiere.ad.dao;

/*
* #%L
* de.metas.adempiere.adempiere.base
* %%
* Copyright (C) 2015 metas GmbH
* Copyright (C) 2020 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Expand All @@ -22,11 +20,9 @@
* #L%
*/

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Properties;
package org.adempiere.ad.dao;

import de.metas.util.lang.RepoIdAware;
import org.adempiere.ad.dao.impl.ActiveRecordQueryFilter;
import org.adempiere.ad.dao.impl.CompareQueryFilter;
import org.adempiere.ad.dao.impl.CompareQueryFilter.Operator;
Expand All @@ -36,7 +32,11 @@
import org.adempiere.model.ModelColumn;
import org.compiere.model.IQuery;

import de.metas.util.lang.RepoIdAware;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Properties;

public interface ICompositeQueryFilter<T> extends IQueryFilter<T>
{
Expand All @@ -55,7 +55,6 @@ public interface ICompositeQueryFilter<T> extends IQueryFilter<T>
ICompositeQueryFilter<T> setDefaultAccept(boolean defaultAccept);

/**
*
* @return default behavior in case this composite is empty
*/
boolean isDefaultAccept();
Expand All @@ -71,14 +70,12 @@ public interface ICompositeQueryFilter<T> extends IQueryFilter<T>
int getFiltersCount();

/**
*
* @return true if the JOIN method is AND
* @see #setJoinAnd()
*/
boolean isJoinAnd();

/**
*
* @return true if the JOIN method is OR
* @see #setJoinOr()
*/
Expand Down Expand Up @@ -219,14 +216,11 @@ public interface ICompositeQueryFilter<T> extends IQueryFilter<T>
/**
* Add a {@link CompareQueryFilter}
*
* @param columnName
* @param operator
* @param value
* @return this
*/
ICompositeQueryFilter<T> addCompareFilter(String columnName, CompareQueryFilter.Operator operator, Object value);
ICompositeQueryFilter<T> addCompareFilter(String columnName, CompareQueryFilter.Operator operator, @Nullable Object value);

ICompositeQueryFilter<T> addCompareFilter(ModelColumn<T, ?> column, CompareQueryFilter.Operator operator, Object value);
ICompositeQueryFilter<T> addCompareFilter(ModelColumn<T, ?> column, CompareQueryFilter.Operator operator, @Nullable Object value);

ICompositeQueryFilter<T> addCompareFilter(String columnName, Operator operator, Object value, IQueryFilterModifier modifier);

Expand All @@ -235,13 +229,11 @@ public interface ICompositeQueryFilter<T> extends IQueryFilter<T>
/**
* Add a {@link EqualsQueryFilter}
*
* @param columnName
* @param value
* @return this
*/
ICompositeQueryFilter<T> addEqualsFilter(String columnName, Object value);
ICompositeQueryFilter<T> addEqualsFilter(String columnName, @Nullable Object value);

ICompositeQueryFilter<T> addEqualsFilter(ModelColumn<T, ?> column, Object value);
ICompositeQueryFilter<T> addEqualsFilter(ModelColumn<T, ?> column, @Nullable Object value);

/**
* Add a {@link EqualsQueryFilter}
Expand Down Expand Up @@ -335,19 +327,16 @@ public interface ICompositeQueryFilter<T> extends IQueryFilter<T>
List<IQueryFilter<T>> getFilters();

/**
*
* @return a readonly list of current nonSQL filters (i.e. which are NOT implementing {@link ISqlQueryFilter} interface).
*/
List<IQueryFilter<T>> getNonSqlFilters();

/**
*
* @return a readonly list of current SQL filters (i.e. which are implementing {@link ISqlQueryFilter} interface).
*/
List<ISqlQueryFilter> getSqlFilters();

/**
*
* @return true if all inner filters are {@link ISqlQueryFilter}s. In this case {@link #getNonSqlFilters()} shall return an empty list.
*/
boolean isPureSql();
Expand All @@ -374,7 +363,7 @@ public interface ICompositeQueryFilter<T> extends IQueryFilter<T>

/**
* Gets an query filter which behaves like {@link #getNonSqlFilters()} list.
*
* <p>
* If there are no nonSQL filters, this method will return null.
*
* @return query filter or null
Expand All @@ -390,7 +379,7 @@ public interface ICompositeQueryFilter<T> extends IQueryFilter<T>

/**
* Converts this filter to an {@link ISqlQueryFilter} if {@link #isPureSql()}.
*
* <p>
* If this is not a pure SQL filter, an exception will be thrown.
*
* @return
Expand Down
@@ -1,10 +1,8 @@
package org.adempiere.ad.dao.impl;

/*
* #%L
* de.metas.adempiere.adempiere.base
* %%
* Copyright (C) 2015 metas GmbH
* Copyright (C) 2020 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Expand All @@ -22,6 +20,8 @@
* #L%
*/

package org.adempiere.ad.dao.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -494,7 +494,7 @@ public ICompositeQueryFilter<T> addEqualsFilter(final String columnName, @Nullab
}

@Override
public ICompositeQueryFilter<T> addEqualsFilter(final ModelColumn<T, ?> column, final Object value)
public ICompositeQueryFilter<T> addEqualsFilter(final ModelColumn<T, ?> column, @Nullable final Object value)
{
final EqualsQueryFilter<T> filter = new EqualsQueryFilter<>(column.getColumnName(), value);
return addFilter(filter);
Expand Down Expand Up @@ -571,14 +571,14 @@ public ICompositeQueryFilter<T> addNotNull(final ModelColumn<T, ?> column)
}

@Override
public ICompositeQueryFilter<T> addCompareFilter(final String columnName, final CompareQueryFilter.Operator operator, final Object value)
public ICompositeQueryFilter<T> addCompareFilter(final String columnName, final Operator operator, final @Nullable Object value)
{
final CompareQueryFilter<T> filter = new CompareQueryFilter<>(columnName, operator, value);
return addFilter(filter);
}

@Override
public ICompositeQueryFilter<T> addCompareFilter(final ModelColumn<T, ?> column, final CompareQueryFilter.Operator operator, final Object value)
public ICompositeQueryFilter<T> addCompareFilter(final ModelColumn<T, ?> column, final Operator operator, final @Nullable Object value)
{
final CompareQueryFilter<T> filter = new CompareQueryFilter<>(column.getColumnName(), operator, value);
return addFilter(filter);
Expand Down
Expand Up @@ -671,11 +671,8 @@ public static void save(final Object model, final String trxName)

/**
* Get context from model.
*
* @param model
* @return
*/
public static Properties getCtx(final Object model)
public static Properties getCtx(@Nullable final Object model)
{
return getCtx(model, false);
}
Expand Down Expand Up @@ -717,7 +714,7 @@ else if (model instanceof Properties)
* IMPORTANT: only call with <b>model interfaces</b> such as {@code I_AD_Table}, {@code C_Order} (legacy classes like `MProduct` and {@link IContextAware}s will also work) and the like.
* Despite the parameter type being "Object" it does not work with all objects.
*/
public static String getTrxName(final Object model)
public static String getTrxName(@Nullable final Object model)
{
final boolean ignoreIfNotHandled = false;
return getTrxName(model, ignoreIfNotHandled);
Expand Down
@@ -1,12 +1,8 @@
package de.metas.handlingunits;

import java.time.ZonedDateTime;

/*
* #%L
* de.metas.handlingunits.base
* %%
* Copyright (C) 2015 metas GmbH
* Copyright (C) 2020 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Expand All @@ -24,13 +20,7 @@
* #L%
*/

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Properties;

import org.compiere.model.I_M_Product;
package de.metas.handlingunits;

import de.metas.bpartner.BPartnerId;
import de.metas.handlingunits.model.I_M_HU;
Expand All @@ -39,9 +29,18 @@
import de.metas.handlingunits.model.I_M_HU_PI_Item_Product;
import de.metas.product.ProductId;
import de.metas.util.ISingletonService;
import lombok.NonNull;
import org.compiere.model.I_M_Product;

import javax.annotation.Nullable;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Properties;

/**
*
* This DAO's methods all use a standard ordering which is relevant if a list of items is returned, or (even more relevant) if only the first one out of many matching records is returned. This
* standard ordering for I_M_HU_PI_Item_Product's is as follows:
* <ul>
Expand All @@ -51,7 +50,6 @@
* <li><code>M_Product_ID DESC, NULLS LAST</code>, i.e. records with a product are preferred</li>
* <li><code>ValidFrom DESC NULLS LAST</code>, i.e. move recent records are preferred</li>
* </ul>
*
*/
public interface IHUPIItemProductDAO extends ISingletonService
{
Expand All @@ -68,24 +66,16 @@ public interface IHUPIItemProductDAO extends ISingletonService
* this DAO's standard ordering (see class-javadoc) and the first one is returned.
* <p>
* Note that the {@code C_BPArtner_ID} is taken from the given {@code huItem}'s {@link I_M_HU}.
*
* @param huItem
* @param productId
* @param date
* @return
*/
@Nullable
I_M_HU_PI_Item_Product retrievePIMaterialItemProduct(I_M_HU_Item huItem, ProductId productId, ZonedDateTime date);

/**
* Retrieves a I_M_HU_PI_Item_Product for the given <code>huItem</code>, <code>product</code> and <code>date</code>. If there are multiple records for the given parameters, they are ordered using
* this DAO's standard ordering (see class-javadoc) and the first one is returned. Attempt to match partner if available.
*
* @param huItem
* @param productId
* @param date
* @return
*/
I_M_HU_PI_Item_Product retrievePIMaterialItemProduct(I_M_HU_PI_Item itemDef, BPartnerId partnerId, ProductId productId, ZonedDateTime date);
@Nullable
I_M_HU_PI_Item_Product retrievePIMaterialItemProduct(@NonNull I_M_HU_PI_Item itemDef, @Nullable BPartnerId partnerId, @NonNull ProductId productId, @Nullable ZonedDateTime date);

I_M_HU_PI_Item_Product retrieveVirtualPIMaterialItemProduct(Properties ctx);

Expand All @@ -95,8 +85,8 @@ public interface IHUPIItemProductDAO extends ISingletonService
*
* @param productId
* @param bpartner
* @param date date on which the item shall be valid
* @param huUnitType (TU or LU)
* @param date date on which the item shall be valid
* @param huUnitType (TU or LU)
* @param allowInfiniteCapacity if false, then the retrieved product is guaranteed to have <code>IsInfiniteCapacity</code> being <code>false</code>.
* @return
*/
Expand All @@ -111,18 +101,16 @@ public interface IHUPIItemProductDAO extends ISingletonService
* @param date
* @param huUnitType
* @param allowInfiniteCapacity
* @param packagingProductId optional, may be <code>null</code>. <br>
* If <code>null</code> then this method behaves like {@link #retrieveMaterialItemProduct(ProductId, BPartnerId, Date, String, boolean)}.
* @param packagingProductId optional, may be <code>null</code>. <br>
* If <code>null</code> then this method behaves like {@link #retrieveMaterialItemProduct(ProductId, BPartnerId, Date, String, boolean)}.
* @return
*
* @task https://metasfresh.atlassian.net/browse/FRESH-386
*/
I_M_HU_PI_Item_Product retrieveMaterialItemProduct(ProductId productId, BPartnerId bpartnerId, ZonedDateTime date, String huUnitType, boolean allowInfiniteCapacity, ProductId packagingProductId);
I_M_HU_PI_Item_Product retrieveMaterialItemProduct(ProductId productId, BPartnerId bpartnerId, ZonedDateTime date, String huUnitType, boolean allowInfiniteCapacity, @Nullable ProductId packagingProductId);

List<I_M_HU_PI_Item_Product> retrieveHUItemProducts(Properties ctx, IHUPIItemProductQuery queryVO, String trxName);

/**
*
* @param ctx
* @param itemProducts
* @param queryVO
Expand Down Expand Up @@ -155,7 +143,7 @@ public interface IHUPIItemProductDAO extends ISingletonService

/**
* Retrieve available {@link I_M_HU_PI_Item_Product}s for TUs which are matching our product and bpartner.
*
* <p>
* NOTE: the default bpartner's TU, if any, will be returned first.
*/
List<I_M_HU_PI_Item_Product> retrieveTUs(Properties ctx, ProductId cuProductId, BPartnerId bpartnerId, boolean allowInfiniteCapacity);
Expand Down

0 comments on commit 7d2fce1

Please sign in to comment.