Skip to content

Commit

Permalink
consider SSC18 when fetching HU's barcode
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Apr 15, 2017
1 parent 20975a6 commit 638780c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/main/java/de/metas/ui/web/handlingunits/HUDocumentView.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import org.compiere.model.I_C_UOM;
import org.compiere.util.Env;

import com.google.common.base.Preconditions;

import de.metas.adempiere.model.I_M_Product;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.handlingunits.model.X_M_HU;
import de.metas.handlingunits.storage.IHUProductStorage;
import de.metas.ui.web.exceptions.EntityNotFoundException;
import de.metas.ui.web.view.ForwardingDocumentView;
import de.metas.ui.web.view.IDocumentView;
import de.metas.ui.web.window.datatypes.LookupValue;
Expand Down Expand Up @@ -85,6 +84,12 @@ public List<HUDocumentView> getIncludedDocuments()
return getIncludedDocuments(HUDocumentView.class);
}

@Override
public HUDocumentViewAttributes getAttributes() throws EntityNotFoundException
{
return HUDocumentViewAttributes.cast(super.getAttributes());
}

/**
*
* @return the ID of the wrapped HU or a value {@code <= 0} if there is none.
Expand Down Expand Up @@ -276,23 +281,36 @@ public String getBarcode()
return null;
}

// TODO: try fetching SSCC first!
//
// Try fetching SSCC first!
final String sscc18 = getAttributes().getSSCC18().orElse(null);
if (sscc18 != null)
{
return sscc18;
}

//
// Use HU's code (i.e. M_HU.Value)
final String huCode = getValue();
return huCode;
}

public boolean matchesBarcode(final String barcodeToMatch)
{
Preconditions.checkArgument(barcodeToMatch != null && !barcodeToMatch.isEmpty(), "invalid barcodeToMatch: %s", barcodeToMatch);
if (Check.isEmpty(barcodeToMatch, true))
{
throw new IllegalArgumentException("Invalid barcode: " + barcodeToMatch);
}

final String barcodeToMatchNormalized = barcodeToMatch.trim();

final String huBarcode = getBarcode();
if (huBarcode == null)
{
return false;
}

return Objects.equals(huBarcode, barcodeToMatch);
return Objects.equals(huBarcode, barcodeToMatchNormalized);
}

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package de.metas.ui.web.handlingunits;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.adempiere.mm.attributes.spi.IAttributeValueContext;
import org.adempiere.mm.attributes.spi.impl.DefaultAttributeValueContext;
import org.adempiere.util.Check;
import org.adempiere.util.GuavaCollectors;
import org.adempiere.util.Services;
import org.adempiere.util.lang.ExtendedMemorizingSupplier;
import org.compiere.model.I_M_Attribute;
import org.compiere.model.X_M_Attribute;
import org.compiere.util.Env;

import com.google.common.base.MoreObjects;

import de.metas.handlingunits.IHUAware;
import de.metas.handlingunits.attribute.IAttributeValue;
import de.metas.handlingunits.attribute.storage.IAttributeStorage;
import de.metas.handlingunits.attribute.storage.IAttributeStorageListener;
import de.metas.handlingunits.attributes.sscc18.ISSCC18CodeDAO;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.handlingunits.model.X_M_HU;
import de.metas.ui.web.view.IDocumentViewAttributes;
Expand Down Expand Up @@ -63,6 +68,11 @@

/* package */ class HUDocumentViewAttributes implements IDocumentViewAttributes
{
public static final HUDocumentViewAttributes cast(final IDocumentViewAttributes attributes)
{
return (HUDocumentViewAttributes)attributes;
}

private final DocumentPath documentPath;
private final IAttributeStorage attributesStorage;

Expand Down Expand Up @@ -243,6 +253,22 @@ public LookupValuesList getAttributeDropdown(final String attributeName)
.map(itemNP -> LookupValue.fromNamePair(itemNP))
.collect(LookupValuesList.collect());
}

public Optional<String> getSSCC18()
{
final I_M_Attribute sscc18Attribute = Services.get(ISSCC18CodeDAO.class).retrieveSSCC18Attribute(Env.getCtx());
if (!attributesStorage.hasAttribute(sscc18Attribute))
{
return Optional.empty();
}
final String sscc18 = attributesStorage.getValueAsString(sscc18Attribute);
if(Check.isEmpty(sscc18, true))
{
return Optional.empty();
}

return Optional.of(sscc18.trim());
}

/**
* Intercepts {@link IAttributeStorage} events and forwards them to {@link Execution#getCurrentDocumentChangesCollector()}.
Expand Down

0 comments on commit 638780c

Please sign in to comment.