Skip to content

Commit

Permalink
connect transaction-candidate to the originally anticipated candidate (
Browse files Browse the repository at this point in the history
…#10328)

* connect transaction-candidate to the originally anticipated candidate

also
* add relation-type
* fix some (potential) glitches
#10327

* Update backend/de.metas.material/planning/src/main/java/de/metas/material/planning/pporder/PPOrderDemandMatcher.java
  • Loading branch information
metas-ts committed Nov 30, 2020
1 parent e6ac04e commit e08ba48
Show file tree
Hide file tree
Showing 21 changed files with 821 additions and 308 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package de.metas.document.engine;

import java.util.Set;

import javax.annotation.Nullable;

import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.X_C_Order;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import de.metas.util.Check;
import de.metas.util.lang.ReferenceListAwareEnum;
import de.metas.util.lang.ReferenceListAwareEnums;
import lombok.Getter;
import lombok.NonNull;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.X_C_Order;

import javax.annotation.Nullable;
import java.util.Set;

/*
* #%L
Expand Down Expand Up @@ -67,7 +65,7 @@ public enum DocStatus implements ReferenceListAwareEnum

public static DocStatus ofNullableCode(@Nullable final String code)
{
return code != null ? ofCode(code) : null;
return Check.isNotBlank(code) ? ofCode(code) : null;
}

public static DocStatus ofNullableCodeOrUnknown(@Nullable final String code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
* #L%
*/

import java.util.List;

import org.adempiere.ad.element.api.AdWindowId;

import java.util.List;

/**
*
* @author Tobias Schoeneberg, www.metas.de - FR [ 2897194 ] Advanced Zoom and RelationTypes
Expand All @@ -49,10 +49,6 @@ public interface IZoomProvider
*
* @param source the source we need zoom targets for
* @param targetAD_Window_ID optional target window ID; if specified, only those {@link ZoomInfo}s will be returned which have this targetAD_Window_ID.
* @param checkRecordsCount
* Set to <code>true</code> if we also need the records count.
* In this case those ZoomInfos with ZERO records would be skipped.
* WARNING, this might be an expensive operation.
* @return a list of zoom targets. The {@link ZoomInfo#getRecordCount()} of the ZoomInfo's query member might be zero.
*/
List<ZoomInfoCandidate> retrieveZoomInfos(IZoomSource source, final AdWindowId targetAD_Window_ID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package de.metas.document.references;

import java.util.List;
import java.util.Properties;
import java.util.function.IntSupplier;

import javax.annotation.Nullable;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import de.metas.adempiere.service.IColumnBL;
import de.metas.i18n.ITranslatableString;
import de.metas.logging.LogManager;
import de.metas.util.Check;
import de.metas.util.Services;
import de.metas.util.lang.Priority;
import lombok.NonNull;
import lombok.ToString;
import lombok.Value;
import org.adempiere.ad.element.api.AdWindowId;
import org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound;
import org.adempiere.ad.expression.api.IStringExpression;
Expand All @@ -26,18 +31,10 @@
import org.compiere.util.Evaluatee;
import org.slf4j.Logger;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;

import de.metas.adempiere.service.IColumnBL;
import de.metas.i18n.ITranslatableString;
import de.metas.logging.LogManager;
import de.metas.util.Check;
import de.metas.util.Services;
import de.metas.util.lang.Priority;
import lombok.NonNull;
import lombok.ToString;
import lombok.Value;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Properties;
import java.util.function.IntSupplier;

/*
* #%L
Expand Down Expand Up @@ -80,7 +77,7 @@ public static final Builder builder()

private final Priority zoomInfoPriority = Priority.MEDIUM;

private RelationTypeZoomProvider(final Builder builder)
private RelationTypeZoomProvider(@NonNull final Builder builder)
{
directed = builder.isDirected();
zoomInfoId = builder.getZoomInfoId();
Expand Down Expand Up @@ -138,10 +135,8 @@ public List<ZoomInfoCandidate> retrieveZoomInfos(

display = referenceTarget.getRoleDisplayName(adWindowId);
}

else
{

final IPair<ZoomProviderDestination, ZoomProviderDestination> sourceAndTarget = findSourceAndTargetEffective(zoomOrigin);

final ZoomProviderDestination source = sourceAndTarget.getLeft();
Expand All @@ -151,7 +146,7 @@ public List<ZoomInfoCandidate> retrieveZoomInfos(

if (!source.matchesAsSource(zoomOrigin))
{
logger.trace("Skip {} because {} is not matching source={}", this, zoomOrigin, source);
logger.debug("Skip {} because {} is not matching source={}", this, zoomOrigin, source);
return ImmutableList.of();
}

Expand Down Expand Up @@ -395,12 +390,6 @@ private static IntSupplier createRecordsCountSupplier(final MQuery query)
/**
* Retrieve destinations for the zoom origin given as parameter.
* NOTE: This is not suitable for TableRecordIdTarget relation types, only for the default kind!
*
* @param ctx
* @param zoomOriginPO
* @param clazz
* @param trxName
* @return
*/
public <T> List<T> retrieveDestinations(final Properties ctx, final PO zoomOriginPO, final Class<T> clazz, final String trxName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.adempiere.mm.attributes.api;

import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import de.metas.material.event.commons.AttributeKeyPartType;
import de.metas.material.event.commons.AttributesKey;
Expand Down Expand Up @@ -129,7 +129,7 @@ else if (X_M_Attribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType))
*/
public static Optional<AttributesKey> createAttributesKeyFromASIAllAttributes(@NonNull final AttributeSetInstanceId attributeSetInstanceId)
{
return createAttributesKeyFromASI(attributeSetInstanceId, Predicates.alwaysTrue());
return createAttributesKeyFromASI(attributeSetInstanceId, i_m_attributeInstance -> true);
}

/**
Expand Down Expand Up @@ -159,7 +159,7 @@ private static Optional<AttributesKey> createAttributesKeyFromASI(
final ImmutableSet<AttributesKeyPart> parts = attributesRepo().retrieveAttributeInstances(attributeSetInstanceId)
.stream()
.filter(additionalFilter)
.map(ai -> createAttributesKeyPart(ai))
.map(AttributesKeys::createAttributesKeyPart)
.filter(Objects::nonNull)
.collect(ImmutableSet.toImmutableSet());

Expand Down Expand Up @@ -193,7 +193,7 @@ else if (X_M_Attribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType))
{
return null;
}
final BigDecimal valueBD = isNull ? null : ai.getValueNumber();
final BigDecimal valueBD = ai.getValueNumber();
return AttributesKeyPart.ofNumberAttribute(attributeId, valueBD);
}
else if (X_M_Attribute.ATTRIBUTEVALUETYPE_Date.equals(attributeValueType))
Expand Down Expand Up @@ -272,4 +272,13 @@ else if (part.getType() == AttributeKeyPartType.AttributeValueId)
.setParameter("attributesKey", attributesKey);
}
}

public static AttributesKey pruneEmptyParts(@NonNull final AttributesKey attributesKey)
{
final ImmutableList<AttributesKeyPart> notBlankParts = attributesKey.getParts().stream()
.filter(p -> Check.isNotBlank(p.getValue()))
.collect(ImmutableList.toImmutableList());

return AttributesKey.ofParts(notBlankParts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public Builder attributeValue(@NonNull final AttributeId attributeId, final Obje
public Builder attributeValue(
@NonNull final AttributeId attributeId,
final Object attributeValue,
final AttributeValueId attributeValueId)
@Nullable final AttributeValueId attributeValueId)
{
final I_M_Attribute attribute = attributesRepo().getAttributeById(attributeId);
attributeValue(attribute, attributeValue, attributeValueId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@

public class AttributesKeysTest
{
/** Watches the current tests and dumps the database to console in case of failure */
/**
* Watches the current tests and dumps the database to console in case of failure
*/
@Rule
public final TestWatcher testWatcher = new AdempiereTestWatcher();

Expand Down Expand Up @@ -167,6 +169,16 @@ public void test_ImmutableAttributeSet_to_AttributeKey_to_ImmutableAttributeSet(
assertThat(attributeSet2).isEqualTo(attributeSet);
}

@Test
void pruneEmptyParts()
{
final AttributesKey attributesKey = AttributesKey.ofString("540044=§&§540047=");

final AttributesKey pruned = AttributesKeys.pruneEmptyParts(attributesKey);

assertThat(pruned).isEqualTo(AttributesKey.NONE);
}

@Nested
public class createAttributesKeyFromAttributeSet
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,23 @@
import de.metas.document.engine.IDocument;
import de.metas.document.engine.IDocumentBL;
import de.metas.i18n.IMsgBL;
import de.metas.material.event.PostMaterialEventService;
import de.metas.material.event.pporder.PPOrderChangedEvent;
import de.metas.material.planning.pporder.IPPOrderBOMBL;
import de.metas.material.planning.pporder.IPPOrderBOMDAO;
import de.metas.material.planning.pporder.LiberoException;
import de.metas.material.planning.pporder.PPOrderId;
import de.metas.material.planning.pporder.PPOrderPojoConverter;
import de.metas.material.planning.pporder.PPOrderQuantities;
import de.metas.report.DocumentReportService;
import de.metas.report.ReportResultData;
import de.metas.report.StandardDocumentReportType;
import de.metas.util.Services;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.Adempiere;
import org.compiere.SpringContextHolder;
import org.compiere.model.I_C_DocType;
import org.compiere.model.MDocType;
import org.compiere.model.ModelValidationEngine;
import org.compiere.model.ModelValidator;
import org.compiere.model.Query;
import org.compiere.model.X_C_DocType;
import de.metas.report.StandardDocumentReportType;
import org.compiere.util.DB;
import org.compiere.util.TimeUtil;
import org.eevolution.api.ActivityControlCreateRequest;
Expand All @@ -72,7 +68,6 @@
import org.eevolution.api.IPPOrderRoutingRepository;
import org.eevolution.api.PPOrderRouting;
import org.eevolution.api.PPOrderRoutingActivity;
import org.eevolution.model.validator.PPOrderChangedEventFactory;

import java.io.File;
import java.math.BigDecimal;
Expand Down Expand Up @@ -356,9 +351,11 @@ public boolean closeIt()
{
ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_CLOSE);

final PPOrderChangedEventFactory eventFactory = PPOrderChangedEventFactory.newWithPPOrderBeforeChange(
SpringContextHolder.instance.getBean(PPOrderPojoConverter.class),
this);
// Let's not send PPOrderChangedEvents for now, because the interesting stuff is already send when the M_Transactions happen.
// It might later turn out that it makes sense to send just the info that a PP_Order was "Closed" though.
// final PPOrderChangedEventFactory eventFactory = PPOrderChangedEventFactory.newWithPPOrderBeforeChange(
// SpringContextHolder.instance.getBean(PPOrderPojoConverter.class),
// this);

//
// Check already closed
Expand Down Expand Up @@ -418,11 +415,11 @@ public boolean closeIt()
// Call Model Validator: AFTER_CLOSE
ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_CLOSE);

final PPOrderChangedEvent changeEvent = eventFactory
.inspectPPOrderAfterChange();

final PostMaterialEventService materialEventService = Adempiere.getBean(PostMaterialEventService.class);
materialEventService.postEventAfterNextCommit(changeEvent);
// final PPOrderChangedEvent changeEvent = eventFactory
// .inspectPPOrderAfterChange();
//
// final PostMaterialEventService materialEventService = Adempiere.getBean(PostMaterialEventService.class);
// materialEventService.postEventAfterNextCommit(changeEvent);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package org.eevolution.model.validator;

import java.sql.Timestamp;

import de.metas.document.DocTypeId;
import de.metas.document.IDocTypeDAO;
import de.metas.document.sequence.IDocumentNoBuilderFactory;
import de.metas.material.event.PostMaterialEventService;
import de.metas.material.planning.pporder.IPPOrderBOMBL;
import de.metas.material.planning.pporder.IPPOrderBOMDAO;
import de.metas.material.planning.pporder.LiberoException;
import de.metas.material.planning.pporder.PPOrderId;
import de.metas.material.planning.pporder.PPOrderPojoConverter;
import de.metas.order.IOrderBL;
import de.metas.order.OrderLineId;
import de.metas.product.IProductBL;
import de.metas.product.ProductId;
import de.metas.project.ProjectId;
import de.metas.uom.UomId;
import de.metas.util.Services;
import lombok.NonNull;
import org.adempiere.ad.callout.spi.IProgramaticCalloutProvider;
import org.adempiere.ad.modelvalidator.ModelChangeType;
import org.adempiere.ad.modelvalidator.annotations.Init;
Expand All @@ -23,24 +38,7 @@
import org.eevolution.model.I_PP_Order;
import org.eevolution.model.X_PP_Order;

import de.metas.document.DocTypeId;
import de.metas.document.IDocTypeDAO;
import de.metas.document.sequence.IDocumentNoBuilderFactory;
import de.metas.material.event.PostMaterialEventService;
import de.metas.material.event.pporder.PPOrderChangedEvent;
import de.metas.material.planning.pporder.IPPOrderBOMBL;
import de.metas.material.planning.pporder.IPPOrderBOMDAO;
import de.metas.material.planning.pporder.LiberoException;
import de.metas.material.planning.pporder.PPOrderId;
import de.metas.material.planning.pporder.PPOrderPojoConverter;
import de.metas.order.IOrderBL;
import de.metas.order.OrderLineId;
import de.metas.product.IProductBL;
import de.metas.product.ProductId;
import de.metas.project.ProjectId;
import de.metas.uom.UomId;
import de.metas.util.Services;
import lombok.NonNull;
import java.sql.Timestamp;

@Interceptor(I_PP_Order.class)
public class PP_Order
Expand Down Expand Up @@ -202,15 +200,17 @@ public void updateAndPostEventOnQtyEnteredChange(final I_PP_Order ppOrderRecord)
throw new LiberoException("Cannot quantity is not allowed because there is something already processed on this order"); // TODO: trl
}

final PPOrderChangedEventFactory eventFactory = PPOrderChangedEventFactory.newWithPPOrderBeforeChange(ppOrderConverter, ppOrderRecord);
// Let's not send PPOrderChangedEvents for now, because the interesting stuff is already send when the M_Transactions happen.
// It might later turn out that it makes sense to send just the info that a PP_Order was "Closed" though.
// final PPOrderChangedEventFactory eventFactory = PPOrderChangedEventFactory.newWithPPOrderBeforeChange(ppOrderConverter, ppOrderRecord);

final PPOrderId orderId = PPOrderId.ofRepoId(ppOrderRecord.getPP_Order_ID());
deleteWorkflowAndBOM(orderId);
createWorkflowAndBOM(ppOrderRecord);

final PPOrderChangedEvent event = eventFactory.inspectPPOrderAfterChange();

materialEventService.postEventAfterNextCommit(event);
// final PPOrderChangedEvent event = eventFactory.inspectPPOrderAfterChange();
//
// materialEventService.postEventAfterNextCommit(event);
}

private void deleteWorkflowAndBOM(final PPOrderId orderId)
Expand Down

0 comments on commit e08ba48

Please sign in to comment.