Skip to content

Commit

Permalink
when evaluating process parameters exclude Processed, Processing and …
Browse files Browse the repository at this point in the history
…IsActive fields

#392
  • Loading branch information
teosarca committed May 18, 2017
1 parent 4bee39e commit 3074eac
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.metas.process.IADPInstanceDAO;
import de.metas.process.ProcessInfoParameter;
import de.metas.ui.web.exceptions.EntityNotFoundException;
import de.metas.ui.web.window.WindowConstants;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.LookupValue;
import de.metas.ui.web.window.descriptor.DocumentEntityDescriptor;
Expand Down Expand Up @@ -130,7 +131,10 @@ public Document createNewDocument(final DocumentEntityDescriptor parametersDescr
Document createNewParametersDocument(final DocumentEntityDescriptor parametersDescriptor, final DocumentId adPInstanceId, final IDocumentEvaluatee evalCtx)
{
return Document.builder(parametersDescriptor)
.setShadowParentDocumentEvaluatee(evalCtx)
.setShadowParentDocumentEvaluatee(evalCtx.excludingFields(
WindowConstants.FIELDNAME_Processed,
WindowConstants.FIELDNAME_Processing,
WindowConstants.FIELDNAME_IsActive))
.initializeAsNewDocument(adPInstanceId, VERSION_DEFAULT);
}

Expand Down
31 changes: 26 additions & 5 deletions src/main/java/de/metas/ui/web/window/model/DocumentEvaluatee.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Optional;
import java.util.Properties;

import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;

import org.adempiere.ad.validationRule.IValidationContext;
Expand All @@ -18,6 +19,7 @@
import org.slf4j.Logger;

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

import de.metas.logging.LogManager;
import de.metas.printing.esb.base.util.Check;
Expand All @@ -28,6 +30,7 @@
import de.metas.ui.web.window.datatypes.json.JSONDate;
import de.metas.ui.web.window.descriptor.DetailId;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import lombok.NonNull;

/*
* #%L
Expand Down Expand Up @@ -56,22 +59,23 @@
private static final Logger logger = LogManager.getLogger(DocumentEvaluatee.class);

private final Document _document;

//
// Scope
private final String _fieldNameInScope;
private final ImmutableSet<String> _fieldNamesToExclude;


/* package */ DocumentEvaluatee(@NotNull final Document document)
{
_document = document; // note: we assume it's not null
_fieldNameInScope = null;
_fieldNamesToExclude = ImmutableSet.of();
}

private DocumentEvaluatee(@NotNull final Document document, final String fieldNameInScope)
private DocumentEvaluatee(@NotNull final Document document, @Nullable final String fieldNameInScope, @NonNull final ImmutableSet<String> fieldNamesToExclude)
{
super();
_document = document; // note: we assume it's not null
_fieldNameInScope = fieldNameInScope; // null is also ok
_fieldNamesToExclude = fieldNamesToExclude;
}

@Override
Expand All @@ -92,13 +96,25 @@ public IDocumentEvaluatee fieldInScope(final String fieldNameInScope)
return this;
}

return new DocumentEvaluatee(_document, fieldNameInScope);
return new DocumentEvaluatee(_document, fieldNameInScope, ImmutableSet.of());
}

private final boolean isFieldInScope(final String fieldName)
{
return Objects.equals(_fieldNameInScope, fieldName);
}

@Override
public IDocumentEvaluatee excludingFields(final String ... fieldNamesToExclude)
{
return new DocumentEvaluatee(_document, _fieldNameInScope, ImmutableSet.copyOf(fieldNamesToExclude));
}

private boolean isExcludedField(final String fieldName)
{
return _fieldNamesToExclude.contains(fieldName);
}


private Properties getCtx()
{
Expand Down Expand Up @@ -205,6 +221,11 @@ public Optional<Object> get_ValueIfExists(final String variableName, final Class
{
return Optional.empty();
}

if(isExcludedField(variableName))
{
return Optional.empty();
}

if (WindowConstants.CONTEXTVAR_NextLineNo.equals(variableName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ public interface IDocumentEvaluatee extends Evaluatee
* @return new evaluatee instance which has the given field in scope
*/
IDocumentEvaluatee fieldInScope(String fieldNameInScope);

/**
* Creates a new evaluatee which will exclude given field names.
*
* @param fieldNamesToExclude
*/
IDocumentEvaluatee excludingFields(String... fieldNamesToExclude);
}

0 comments on commit 3074eac

Please sign in to comment.